Skip to content

Commit

Permalink
feat: add a description of the solution to lcof problem: No.03 (doocs…
Browse files Browse the repository at this point in the history
…#678)

面试题 03. 数组中重复的数字
  • Loading branch information
YangFong authored Jan 20, 2022
1 parent ab92560 commit 75d7283
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lcof/面试题03. 数组中重复的数字/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@

## 解法

0 ~ n-1 范围内的数,分别还原到对应的位置上,如:数字 2 交换到下标为 2 的位置。

若交换过程中发现重复,则直接返回。
三种方式

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

<!-- tabs:start -->

Expand Down

0 comments on commit 75d7283

Please sign in to comment.