链表
1
wdt_
即使上线也匆忙,新版本,愁断肠,orz...
展开
-
【链表】B016_LC_奇偶链表(注意奇数个结点)
一、Problem 给定一个单链表,把所有的奇数节点和偶数节点分别排在一起。请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性。 请尝试使用原地算法完成。你的算法的空间复杂度应为 O(1),时间复杂度应为 O(nodes),nodes 为节点总数。 示例 1: 输入: 1->2->3->4->5->NULL 输出: 1->3->5->2->4->NULL 示例 2: 输入: 2->1->3->5-&g原创 2020-07-09 09:22:06 · 245 阅读 · 0 评论 -
【链表】C015_LC_回文链表(双指针 / 利用递归逐层返回)
一、Problem You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum原创 2020-06-30 16:24:52 · 184 阅读 · 0 评论 -
【链表】B014_LC_链表求和(空链表值为 0 / 进阶问题)
一、Problem 二、Solution 方法一:空链表值为 0 和字符串相加一个思想,只要有一个链表不空就一直循环下去,链表的空节点的值默认为 0 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int ca = 0; ListNode dead = new ListNode(-1), cur = dead; while (l1 != null原创 2020-06-30 11:52:39 · 257 阅读 · 0 评论 -
【链表】C013_LC_移除重复节点(hash 表 / 双指针)
一、Problem 编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。 示例1: 输入:[1, 2, 3, 3, 2, 1] 输出:[1, 2, 3] 示例2: 输入:[1, 1, 1, 1, 2] 输出:[1, 2] 提示: 链表长度在[0, 20000]范围内。 链表元素在[0, 20000]范围内。 进阶: 如果不得使用临时缓冲区,该怎么解决? 二、Solution 方法一:超级暴力 class Solution { public ListNode removeDup原创 2020-06-26 22:46:43 · 186 阅读 · 0 评论 -
【链表】B012_LC_从链表中删去总和值为零的连续节点(双指针)
一、Problem Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, return the head of the final linked list. You may return any such answer. (Note that in the exa原创 2020-06-21 10:16:32 · 149 阅读 · 0 评论 -
【链表】C010_合并两个有序链表(暴力 / 双指针思想 / 递归)
一、Problem Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Input: 1->2->4, 1->3->4 Output: 1-&g...原创 2020-05-01 22:50:37 · 198 阅读 · 0 评论 -
【链表】A009_合并K个排序链表(暴力 / PQ / 分治(代办...))
一、Problem Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4-&g...原创 2020-04-26 22:44:01 · 111 阅读 · 0 评论 -
【链表】C008_链表的中间结点(模拟 | 双指针)
一、题目描述 Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. [1,2,3,4,5] [3,4,5] [1,2,3,4,5,6] ...原创 2020-03-23 09:16:05 · 76 阅读 · 0 评论 -
【链表】B007_旋转链表(三次翻转 | 找倒数 k-1 个结点)
一、题目描述 Given a linked list, rotate the list to the right by k places, where k is non-negative. Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: ...原创 2020-03-20 15:06:30 · 112 阅读 · 0 评论 -
【链表】C006_LC_反转链表 (迭代 / 递归)
一、题目描述 Reverse a singly linked list. 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. ...原创 2020-03-02 10:37:28 · 107 阅读 · 0 评论 -
【链表】005 两数相加 (不动头结点)
Hoji的技术博客:在这里随意任性地创作,一首诗、一幅画、一篇文章… 在这里你可以get到但不仅限算法、Spring, SpringBoot等后端技术、MySql,Oracle数据库探索… 博客地址:https://www.hoji.site 一、题目描述 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字。 如果...原创 2019-11-18 16:07:35 · 160 阅读 · 0 评论 -
【练习】链表中的双指针总结
一个模板: while (slow != null && fast != null && fast.next != null) { slow = slow.next; fast = fast.next.next; if (slow == fast) { return true;...原创 2019-09-04 22:43:26 · 181 阅读 · 0 评论 -
【链表】B004_LC_删除链表的倒数第 N 个结点(顺数 N-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, ...原创 2019-09-01 22:31:03 · 132 阅读 · 0 评论 -
【练习】003 — 环形链表 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 ...原创 2019-09-01 01:28:50 · 125 阅读 · 0 评论 -
【链表】002 相交链表(哈希表、双指针)
一、题目 Write a program to find the node at which the intersection of two singly linked lists begins. Example 1: Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3...原创 2019-08-31 22:46:19 · 199 阅读 · 0 评论 -
【哈希表、双指针】001 — 是否是环形链表?
一、题目 给定一个链表,判断链表中是否有环。 输入:head = [3,2,0,-4], pos = 1 输出:true 解释:链表中有一个环,其尾部连接到第二个节点。 二、分析 【1】哈希表 我们可以通过检查一个结点此前是否被访问过来判断链表是否为环形链表。 常用的方法是使用哈希表。 遍历所有结点并在哈希表中存储每个结点的引用(或内存地址)。 【1】 如果当前结点为空结点 null(即已检...原创 2019-08-26 00:20:44 · 175 阅读 · 0 评论