数组、链表和跳表
数组
时间复杂度
| 类型 | 复杂度 |
|---|---|
| prepend | O(1) |
| append | O(1) |
| lookup | O(1) |
| insert | O(N) |
| delete | O(N) |
链表
增加元素

删除节点

双向链表

时间复杂度
| 类型 | 复杂度 |
|---|---|
| preappend | O(1) |
| append | O(1) |
| lookup | O(N) |
| insert | O(1) |
| delete | O(1) |
跳表
链表加速
链表缺陷修复-->
- 升维
- 空间换时间

添加索引

二级索引

五级索引

时间复杂度


小结
- 数组、链表、调表的原理和实现
- 三者的时间复杂度、空间复杂度
- 工程运用
- 跳表:升维思想+空间换时间
练习
步骤:
- 5-10min:读题和思考
- 有思路:自己开始做和写代码;不然,马上蓝题解
- 默写背诵
- 自己写
两数之和题目: https://leetcode-cn.com/problems/two-sum/
Array 实战题目
-
-
解题思路

算法流程:使用双指针i,j,分别位于容器壁两端,根据后面的规则,并且更新最大值area,直到i==j时返回其area证明与规则:- 在每一个状态下,无论长板或短板收窄 1 格,都会导致水槽
底边宽度 -1- 若向内移动短板,水槽的短板 min(h[i], h[j])可能变大,因此水槽面积 S(i,j) 可能增大。
- 若向内移动长板,水槽的短板 min(h[i], h[j])不变或变小,下个水槽的面积一定小于当前水槽面积。
代码
public static int maxArea(int[] height){ if (height == null || height.length < 2) return 0; int area = 0; int left = 0; int right = height.length-1; while (left < right){ area = Math.max(area,(right-left)*Math.min(height[left],height[right])); if (height[left] > height[right]) right--; else if (height[left] < height[right]) left++; else { left++; right--; } } return area; } // leetcode jyd书写的代码 class Solution { public int maxArea(int[] height) { int i = 0, j = height.length - 1, res = 0; while(i < j){ res = height[i] < height[j] ? Math.max(res, (j - i) * height[i++]): Math.max(res, (j - i) * height[j--]); } return res; } } 作者:jyd 链接:https://leetcode-cn.com/problems/container-with-most-water/solution/container-with-most-water-shuang-zhi-zhen-fa-yi-do/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 - 在每一个状态下,无论长板或短板收窄 1 格,都会导致水槽
-
Linked List 实战题目
- leetcode.com/problems/re…
- leetcode.com/problems/sw…
- leetcode.com/problems/li…
- leetcode.com/problems/li…
- leetcode.com/problems/re…
课后作业
- leetcode-cn.com/problems/re…
- leetcode-cn.com/problems/ro…
- leetcode-cn.com/problems/me…
- leetcode-cn.com/problems/me…
- leetcode-cn.com/problems/tw…
- leetcode-cn.com/problems/mo…
- leetcode-cn.com/problems/pl…
参考链接
- Java 源码分析(ArrayList)
- Linked List 的标准实现代码
- [Linked List 示例代码](www.cs.cmu.edu/~adamchik/1… Lists/code/LinkedList.java)
- Java 源码分析(LinkedList)
- LRU Cache - Linked list: LRU 缓存机制
- Redis - Skip List:跳跃表、为啥 Redis 使用跳表(Skip List)而不是使用 Red-Black?