随笔分类 - LinkedList
摘要:You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list
阅读全文
摘要:You have a queue of integers, you need to retrieve the first unique integer in the queue. Implement the FirstUnique class: FirstUnique(int[] nums) Ini
阅读全文
摘要:[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [英文数据结构或算法,为什么不用别的数据结构或算法]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异
阅读全文
摘要:[抄题]: https://practice.geeksforgeeks.org/problems/delete-a-node-in-single-linked-list/1 从前往后,删除第N个 [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇
阅读全文
摘要:[抄题]: Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,
阅读全文
摘要:[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [英文数据结构或算法,为什么不用别的数据结构或算法]: [一句话思路]: 背诵的递归写法 [输入量]:空: 正常情况:特大:特小:程序里处理
阅读全文
摘要:全部 [抄题]: Reverse a singly linked list. [思维问题]: 以为要用dummy node [一句话思路]: 直接全部转过来就行了,用dummy node反而多余 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图
阅读全文
摘要:[抄题]: Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree shoul
阅读全文
摘要:[抄题]: Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts". The length o
阅读全文
摘要:[抄题]: You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes
阅读全文
摘要:[抄题]: Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You
阅读全文
摘要:[抄题]: 设计一种方式检查一个链表是否为回文链表。1->2->1 就是一个回文链表。 [暴力解法]: 时间分析: 空间分析: [思维问题]: 以为要从从后往前扫描,不知道调用reverse函数。其实找中点、翻转都是链表中直接能用的API [一句话思路]: 后半截儿反过来以后,相同就同时走。走到头说
阅读全文
摘要:[抄题]: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --
阅读全文
摘要:[抄题]: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin
阅读全文
摘要:反向存储,从左往右加 [抄题]: 你有两个用链表代表的整数,其中每个节点包含一个数字。数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头。写出一个函数将两个整数相加,用链表形式返回和。给出两个链表 3->1->5->null 和 5->9->2->null,返回 8->0->8->nu
阅读全文
摘要:[抄题]: 给出若干闭合区间,合并所有重叠的部分。 给出的区间列表 => 合并后的区间列表: [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 区间类问题,先把起点排序才能具有逐个合并的能力和性质 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合
阅读全文
摘要:[抄题]: 给你一个链表以及一个k,将这个链表从头指针开始每k个翻转一下。链表元素个数不是k的倍数,最后剩余的不用翻转。 [思维问题]: [一句话思路]: // reverse head->n1->..->nk->next.. // to head->nk->..->n1->next.. // re
阅读全文
摘要:[抄题]: 给出一个链表,每个节点包含一个额外增加的随机指针可以指向链表中的任何节点或空的节点。 返回一个深拷贝的链表。 [思维问题]: [一句话思路]: 完完全全地复制,否则不好操作。 1->1`->2->2`->3->3`->4->4` 紧随其后地复制,再拆开 [输入量]:空: 正常情况:特大:
阅读全文
摘要:方法一:堆 [抄题]: 合并k个排序链表,并且返回合并后的排序链表。尝试分析和描述其复杂度。 [思维问题]: [一句话思路]: 堆的基本操作 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: [总结]: 用比较函数+堆的做法 两
阅读全文
摘要:[抄题]: 给定一个链表,旋转链表,使得每个节点向右移动k个位置,其中k是一个非负数 样例 给出链表1->2->3->4->5->null和k=2 返回4->5->1->2->3->null 给出链表1->2->3->4->5->null和k=2 返回4->5->1->2->3->null [思维问
阅读全文