
链表
张小白不白
博采众长,厚积薄发
展开
-
21.合并两个有序链表
题目将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。示例:输入:1->2->4, 1->3->4输出:1->1->2->3->4->4题目分析本题不涉及复杂的算法和数据结构,可以使用递归思想解答使用循环法时,利用虚拟头节点比较方便代码和注释解法1:递归/** * Defini...原创 2019-11-06 15:42:35 · 124 阅读 · 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 · 137 阅读 · 0 评论 -
206.链表的翻转
题目Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL分析定义虚拟头节点以及p,q两个指针变量,完成每一步的翻转操作这里的虚拟头节点ret并没有指向head,而是充当了中间过度变量的作用代...原创 2019-10-05 21:08:09 · 116 阅读 · 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 = 6Output: 1->2->3->4->5分析本题属于典型的链表节点删除题目,使用虚拟头节...原创 2019-10-05 19:03:11 · 125 阅读 · 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 · 112 阅读 · 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 · 121 阅读 · 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 · 133 阅读 · 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 · 103 阅读 · 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 · 210 阅读 · 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 · 120 阅读 · 0 评论