
链表
张小白不白
博采众长,厚积薄发
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
21.合并两个有序链表
题目 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 题目分析 本题不涉及复杂的算法和数据结构,可以使用递归思想解答 使用循环法时,利用虚拟头节点比较方便 代码和注释 解法1:递归 /** * Defini...原创 2019-11-06 15:42:35 · 134 阅读 · 0 评论 -
287.寻找重复数字
题目 Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,...原创 2019-10-06 17:15:58 · 145 阅读 · 0 评论 -
206.链表的翻转
题目 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 分析 定义虚拟头节点以及p,q两个指针变量,完成每一步的翻转操作 这里的虚拟头节点ret并没有指向head,而是充当了中间过度变量的作用 代...原创 2019-10-05 21:08:09 · 129 阅读 · 0 评论 -
203.删除链表指定元素
题目 Remove all elements from a linked list of integers that have value val. Example: Input: 1->2->6->3->4->5->6, val = 6 Output: 1->2->3->4->5 分析 本题属于典型的链表节点删除题目,使用虚拟头节...原创 2019-10-05 19:03:11 · 136 阅读 · 0 评论 -
202.快乐数
题目 Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares...原创 2019-10-05 14:50:55 · 134 阅读 · 0 评论 -
160.链表交点
题目 Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: 分析 由于连个链表的长度不同,没法直接比较,需要移动指针使两个指针分别在两个链表的相同索引处 可以使用长度相减法...原创 2019-10-05 12:17:42 · 128 阅读 · 0 评论 -
142.环形链表 II
题目 Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use an integer pos which represents the position (0...原创 2019-10-05 11:27:12 · 143 阅读 · 0 评论 -
141.环形链表
题目 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 ...原创 2019-10-05 10:47:57 · 110 阅读 · 0 评论 -
24.成对交换链表节点
题目 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...原创 2019-10-05 09:54:09 · 231 阅读 · 0 评论 -
19.删除链表的倒数第n个节点
题目 Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, t...原创 2019-10-05 08:52:38 · 131 阅读 · 0 评论