Skip to content

Commit 75d7283

Browse files
authored
feat: add a description of the solution to lcof problem: No.03 (doocs#678)
面试题 03. 数组中重复的数字
1 parent ab92560 commit 75d7283

File tree

1 file changed

+10
-3
lines changed
  • lcof/面试题03. 数组中重复的数字

1 file changed

+10
-3
lines changed

lcof/面试题03. 数组中重复的数字/README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@
2222

2323
## 解法
2424

25-
0 ~ n-1 范围内的数,分别还原到对应的位置上,如:数字 2 交换到下标为 2 的位置。
26-
27-
若交换过程中发现重复,则直接返回。
25+
三种方式
26+
27+
- 排序
28+
- 先排序,将相同的数字聚集到一起。
29+
- 再遍历,当位于 `i``i + 1` 的数字相等时,返回该数字。
30+
- 哈希表
31+
- 记录数字在数组中的数量,当数量为 2 时,返回即可。
32+
- 原地交换
33+
- 0 ~ n-1 范围内的数,分别还原到对应的位置上,如:数字 2 交换到下标为 2 的位置。
34+
- 若交换过程中发现重复,则直接返回。
2835

2936
<!-- tabs:start -->
3037

0 commit comments

Comments
 (0)