剑指Offer 03.数组中重复的数字【哈希表、数组交换、排序】

题目描述

找出数组中重复的数字。

在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。

示例 1:

输入:[2, 3, 1, 0, 2, 5, 3]

输出:2 或 3

限制:

2 <= n <= 100000

Read more

python基础

python基础

2020.10.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
r'xxx' ----xxx不发生转义    ('\'转义字符)

100000 ---等价于100_000,添加'_':'_'位置可以任意

浮点数:1.23x10^9 1.23e9
1.23x10^-9 1.23e-9 (e可以大小写)

'''...'''表示多行内容

布尔值 True False (首字符大写)
可进行 and、or、not运算

空值None(不等于0,0有自己的意义)
TODO可以创建自定义数据类型

变量:同一个变量可以反复被赋值,可为不同数据类型
a = 123 # a是整数
print(a)
a = 'ABC' # a变为字符串
print(a)
结果:
123
ABC

常量;变量名默认为全部大写

整数的运算结果永远是精确的,无论整数做//除法还是取余数,结果永远是整数
10/5=2.0
10//5=2
10%3=1

python的整数没有大小限制;
浮点数也没有,但超出一定范围(贼大)就直接表示为inf(无限大)

字符串和编码:

tip

1
2
3
4
5
6
7
8
9
10
11
12
字符串:
对于单个字符的编码,Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符:
>>> ord('A')
65
>>> ord('中')
20013
>>> chr(66)
'B'
>>> chr(25991)
'文'

需要转义,用%%来表示一个%;

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment