随笔分类 -  链表

摘要:https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/ /* struct RandomListNode { int label; struct RandomListNode *next, *random; RandomLis 阅读全文
posted @ 2021-05-14 11:15 米开朗菠萝 阅读(27) 评论(0) 推荐(0)
摘要:class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ stack = [] #存放符号 d = {"]": "[", ")":"(", "}":"{"} “”“ 判断符号是否是结束符号,如果是, 阅读全文
posted @ 2020-02-11 13:53 米开朗菠萝 阅读(73) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no 阅读全文
posted @ 2019-01-30 15:36 米开朗菠萝 阅读(127) 评论(0) 推荐(0)
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文
posted @ 2019-01-30 14:48 米开朗菠萝 阅读(90) 评论(0) 推荐(0)
摘要:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes its 阅读全文
posted @ 2019-01-30 08:40 米开朗菠萝 阅读(96) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: 阅读全文
posted @ 2019-01-25 11:17 米开朗菠萝 阅读(130) 评论(0) 推荐(0)
摘要:# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def partition(self, head, x):... 阅读全文
posted @ 2019-01-15 19:04 米开朗菠萝 阅读(84) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2 Output: 1->2 Example 2: Input: 1- 阅读全文
posted @ 2018-11-29 12:22 米开朗菠萝 阅读(102) 评论(0) 推荐(0)
摘要:python版本: 阅读全文
posted @ 2016-05-25 21:43 米开朗菠萝 阅读(423) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 typedef struct student //声明结构体 5 { 6 int num; 7 struct student *pnext;... 阅读全文
posted @ 2016-05-08 12:22 米开朗菠萝 阅读(1433) 评论(0) 推荐(0)
摘要:1.设立2个指针i,j指向头结点 2.i走1步,j走2步.如果有环,j一定能追上i; 3.如果j不为空,且i和j相等此链表即为有环。 阅读全文
posted @ 2016-05-08 12:18 米开朗菠萝 阅读(359) 评论(0) 推荐(0)
摘要:不考虑单链表有环的情况下 如果2个单链表相交,一定是Y型链表 1.遍历2个链表到尾结点,记录2个链表的长度x,y 2.尾结点相同,则相交。 3.从表头开始,长链表先走|x-y|步,之后2个链表一起走,判断第一个相同的点。 1 #include <stdio.h> 2 #include <stdlib 阅读全文
posted @ 2016-05-08 12:16 米开朗菠萝 阅读(395) 评论(0) 推荐(0)