数组的原理以及实战
不同语言中:
c++: int a[100];
java: int[] a=new int[100];
python:a=[];
特点:
- 数组的基本特点:支持随机访问
- 数组的关键:索引与寻址
获取值:
c++:a[I],*(a[I])
数组中内存中是一段连续的存储空间:
插入元素:
如果你想做数组中C后面插入一个元素D
step1:后移元素
step2:插入
删除元素:
有一个数组 想删去z
step1:删掉z
step2:元素前移
时间复杂度:
lookup o(1)
insert o(n)
delete o(n)
append(push back) o(1)
prepend(push front) o(n)
leetcode:
1.https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
2.https://leetcode-cn.com/problems/move-zeroes/
3.https://leetcode-cn.com/problems/merge-sorted-array/