算法教程

在这里插入图片描述
在这里插入图片描述
四大数据结构:栈、队列、set、map
在这里插入图片描述
线性数据结构:数组 栈、队列 堆 链表

树形结构:数、二叉树 二叉搜索树 哈希表 并查集 字母树 布隆母过滤器 LRUcache

经典的编程、树的遍历、贪心算法、回溯和递归、深度优先广度优先、分治算法、动态规划算法、二分查找、图

时间和空间复杂度
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

5.理论讲解—数组和链表

数组
内容中连续的一端存储区域
在这里插入图片描述
内存管理器可以实现访问任何一个下标的元素,都是O(1)
查询元素:O(1)
在这里插入图片描述
插入元素:平均O(n)
删除元素:平均O(n)
要想改善数组这样的长时间,链表应运而生

链表
分为单链表和双链表
适合于:
1.插入和删除操作非常多
2.你不知道有多少个元素在
在这里插入图片描述
本质上就是一个一个的元素,用指针链接起来
在这里插入图片描述
在这里插入图片描述
查找元素:O(n)
插入元素:O(1)
在这里插入图片描述
删除元素:O(1)
在这里插入图片描述

6.面试题—反转一个单链表

http://leetcode.com/problems/reverse-linked-list/
206. Reverse Linked List
Easy
Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
Follow up:
A linked list can be reversed either iteratively or recursively. Could you implement both?

在这里插入图片描述
http://leetcode.com/problems/swap-nodes-in-pairs
24. Swap Nodes in Pairs
Medium
Given a linked list, swap every two adjacent nodes and return its head.
You may not modify the values in the list’s nodes, only nodes itself may be changed.
Example:
Given 1->2->3->4, you should return the list as 2->1->4->3.
在这里插入图片描述
http://leetcode.com/problems/linked-list-cycle
141. Linked List Cycle
Easy
Given a linked list, determine if it has a cycle in it.
To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list.

Example 1:
Input: head = [3,2,0,-4], pos = 1
Output: true
Explanation: There is a cycle in the linked list, where tail connects to the second node.
在这里插入图片描述
Example 2:
Input: head = [1,2], pos = 0
Output: true
Explanation: There is a cycle in the linked list, where tail connects to the first node.
在这里插入图片描述
Example 3:
Input: head = [1], pos = -1
Output: false
Explanation: There is no cycle in the linked list.
在这里插入图片描述
Follow up:
Can you solve it using O(1) (i.e. constant) memory?

方法一:硬做
方法二:set、判重O(n)
方法三:快慢指针 快指针走两步、慢指针走一步,快慢指针相遇O(n)
在这里插入图片描述

http://leetcode.com/problems/linked-list-sysle-ii

http://leetcode.com/problems/reverse-nodes-in-k-group/

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值