Skip to content

Commit 00ebc5e

Browse files
committed
feat: add lcof and lcci folders
添加《剑指Offer》和《程序员面试金典》目录
1 parent 5ee380a commit 00ebc5e

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

lcci/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 《程序员面试金典》系列
2+
地址:https://leetcode-cn.com/problemset/lcci/

lcof/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 《剑指 Offer》系列
2+
地址:https://leetcode-cn.com/problemset/lcof/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [面试题03. 数组中重复的数字](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/)
2+
3+
## 题目描述
4+
找出数组中重复的数字。
5+
6+
7+
在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。
8+
9+
**示例 1:**
10+
11+
```
12+
输入:
13+
[2, 3, 1, 0, 2, 5, 3]
14+
输出:2 或 3
15+
```
16+
17+
**限制:**
18+
19+
```
20+
2 <= n <= 100000
21+
```
22+
23+
## 解法
24+
### Python3
25+
```python
26+
class Solution:
27+
def findRepeatNumber(self, nums: List[int]) -> int:
28+
for i, num in enumerate(nums):
29+
while i != num:
30+
if num == nums[num]:
31+
return num
32+
nums[i], nums[num] = nums[num], nums[i]
33+
34+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def findRepeatNumber(self, nums: List[int]) -> int:
3+
for i, num in enumerate(nums):
4+
while i != num:
5+
if num == nums[num]:
6+
return num
7+
nums[i], nums[num] = nums[num], nums[i]

0 commit comments

Comments
 (0)