Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9da60df

Browse files
committed
Update 0169. 多数元素.md
1 parent 735bef2 commit 9da60df

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

‎Solutions/0169. 多数元素.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
## 题目大意
1111

12-
**描述**:给定一个大小为 $n$ 的数组 `nums`
12+
**描述**:给定一个大小为 $n$ 的数组 $nums$
1313

14-
**要求**:返回其中相同元素个数最多的元素
14+
**要求**:返回其中的多数元素
1515

1616
**说明**:
1717

18+
- **多数元素**:指在数组中出现次数大于 $\lfloor \frac{n}{2} \rfloor$ 的元素。
1819
- $n == nums.length$。
19-
- 1ドル \le n \le 5 * 10^4$。
20+
- 1ドル \le n \le 5 \times 10^4$。
2021
- $-10^9 \le nums[i] \le 10^9$。
2122

2223
**示例**:
@@ -39,8 +40,8 @@
3940

4041
### 思路 1:哈希表
4142

42-
1. 遍历数组 `nums`
43-
2. 对于当前元素 `num`,用哈希表统计每个元素 `num` 出现的次数。
43+
1. 遍历数组 $nums$
44+
2. 对于当前元素 $num$,用哈希表统计每个元素 $num$ 出现的次数。
4445
3. 再遍历一遍哈希表,找出元素个数最多的元素即可。
4546

4647
### 思路 1:代码
@@ -70,11 +71,11 @@ class Solution:
7071

7172
### 思路 2:分治算法
7273

73-
如果 `num` 是数组 `nums` 的众数,那么我们将 `nums` 分为两部分,则 `num` 至少是其中一部分的众数。
74+
如果 $num$ 是数组 $nums$ 的众数,那么我们将 $nums$ 分为两部分,则 $num$ 至少是其中一部分的众数。
7475

7576
则我们可以用分治法来解决这个问题。具体步骤如下:
7677

77-
1. 将数组 `nums` 递归地将当前序列平均分成左右两个数组,直到所有子数组长度为 `1`
78+
1. 将数组 $nums$ 递归地将当前序列平均分成左右两个数组,直到所有子数组长度为 1ドル$
7879
2. 长度为 1ドル$ 的子数组众数肯定是数组中唯一的数,将其返回即可。
7980
3. 将两个子数组依次向上两两合并。
8081
1. 如果两个子数组的众数相同,则说明合并后的数组众数为:两个子数组的众数。

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /