随笔分类 -  数据结构---链表

摘要:题目链接:https://www.nowcoder.com/practice/0ab593ca56b1476eb05b1ff848fd7fcc?tpId=107&tqId=33419&rp=7&ru=%2Fta%2Fbeginner-programmers&qru=%2Fta%2Fbeginner- 阅读全文
posted @ 2020-04-10 14:52 wydxry 阅读(360) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://www.nowcoder.com/practice/0cff324157a24a7a8de3da7934458e34 题目描述 找出单向链表中的一个节点,该节点到尾指针的距离为K。链表的倒数第0个结点为链表的尾指针。要求时间复杂度为O(n)。链表结点定义如下:struct 阅读全文
posted @ 2020-04-10 00:39 wydxry 阅读(707) 评论(0) 推荐(0) 编辑
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 struct slist 4 { 5 int info; 6 struct slist *next; 7 }; 8 int a[8]={35,46,17,80,25,78,66,54}; 9 struct sl 阅读全文
posted @ 2020-03-24 15:19 wydxry 阅读(1590) 评论(0) 推荐(0) 编辑
摘要:题目描述: 输入一个链表,按链表从尾到头的顺序返回一个ArrayList。 思路:链表逆序放入ArrayList。 1 /** 2 * struct ListNode { 3 * int val; 4 * struct ListNode *next; 5 * ListNode(int x) : 6 阅读全文
posted @ 2020-03-09 10:54 wydxry 阅读(199) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/insertion-sort-list/ 插入排序算法: 插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,并将其 阅读全文
posted @ 2020-03-07 10:56 wydxry 阅读(231) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/linked-list-cycle-lcci/ 给定一个有环链表,实现一个算法返回环路的开头节点。有环链表的定义:在链表中某个节点的next元素指向在它前面出现过的节点,则表明该链表存在环路。 示例 1: 输入:head = 阅读全文
posted @ 2020-03-07 09:47 wydxry 阅读(335) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/reverse-linked-list-ii/ 反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。 说明:1 ≤ m ≤ n ≤ 链表长度。 示例: 输入: 1->2->3->4->5->NULL, m = 2, n 阅读全文
posted @ 2020-03-06 19:13 wydxry 阅读(212) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/reorder-list/ 给定一个单链表 L:L0→L1→…→Ln-1→Ln ,将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→… 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 示例 1 阅读全文
posted @ 2020-03-06 11:39 wydxry 阅读(239) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/partition-list/ 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前。 你应当保留两个分区中每个节点的初始相对位置。 示例: 输入: head = 1->4-> 阅读全文
posted @ 2020-03-04 10:00 wydxry 阅读(159) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/ 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2]输出:[2,3,1] 限制: 阅读全文
posted @ 2020-03-03 23:23 wydxry 阅读(347) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/ 定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 示例: 输入: 1->2->3->4->5->NULL输出: 5->4->3->2->1->NUL 阅读全文
posted @ 2020-03-03 23:18 wydxry 阅读(153) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ 给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字。 示例 1: 输入: 1->2->3->3->4->4->5 阅读全文
posted @ 2020-03-03 17:14 wydxry 阅读(179) 评论(0) 推荐(0) 编辑
摘要:之前的题目是:LeetCode 83. 删除排序链表中的重复元素 我改了下前提条件,排序链表改为非排序链表。 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * struct List 阅读全文
posted @ 2020-03-03 16:40 wydxry 阅读(220) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/rotate-list/ 给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。 示例 1: 输入: 1->2->3->4->5->NULL, k = 2输出: 4->5->1->2->3->NUL 阅读全文
posted @ 2020-03-03 16:21 wydxry 阅读(202) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二 阅读全文
posted @ 2020-03-03 16:01 wydxry 阅读(212) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/sum-lists-lcci/ 给定两个用链表表示的整数,每个节点包含一个数位。 这些数位是反向存放的,也就是个位排在链表首部。 编写函数对这两个整数求和,并用链表形式返回结果。 示例: 输入:(7 -> 1 -> 6) + 阅读全文
posted @ 2020-03-03 09:40 wydxry 阅读(844) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/partition-list-lcci/ 编写程序以 x 为基准分割链表,使得所有小于 x 的节点排在大于或等于 x 的节点之前。如果链表中包含 x,x 只需出现在小于 x 的元素之后(如下所示)。分割元素 x 只需处于“右 阅读全文
posted @ 2020-03-03 09:05 wydxry 阅读(179) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree/ 给定一个单链表,其中的元素按升序排序,将其转换为高度平衡的二叉搜索树。 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的 阅读全文
posted @ 2020-02-28 17:28 wydxry 阅读(192) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/ 给定两个(单向)链表,判定它们是否相交并返回交点。请注意相交的定义基于节点的引用,而不是基于节点的值。换句话说,如果一个链表的第k个节点与另一个链 阅读全文
posted @ 2020-02-28 11:21 wydxry 阅读(226) 评论(0) 推荐(0) 编辑
摘要:题目链接:https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/ 给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。 返回删除后的链表的头节点。 注意:此题对比原题有改动 示例 1: 输入: hea 阅读全文
posted @ 2020-02-27 22:10 wydxry 阅读(229) 评论(0) 推荐(0) 编辑

Live2D