题目链接:反转链表 方法一:递归解法 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} ...
分类:
其他好文 时间:
2020-09-24 21:55:20
阅读次数:
37
struct ListNode* removeElements(struct ListNode* head, int val){ if (head == NULL) { return NULL; } head->next = removeElements(head->next, val); retu ...
分类:
其他好文 时间:
2020-09-17 19:25:01
阅读次数:
24
2. 两数相加 这题medium,但思路挺简单的。模拟下就可以 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ...
分类:
其他好文 时间:
2020-09-17 19:08:34
阅读次数:
21
// 初始化 快指针和慢指针 ListNode slow = head; ListNode fast = head; /** * Change this condition to fit specific problem. * 在这里避免空指针错误 **/ while (slow != null & ...
分类:
其他好文 时间:
2020-08-20 18:57:19
阅读次数:
66
2020.08.05 1、多线程 2、IPC、共享内存 3、bind 4、合并n个有序链表 (力扣原题 使用最小堆会快一些) #include <queue> using namespace std; struct ListNode { int val; ListNode* next; ListNo ...
分类:
其他好文 时间:
2020-08-20 18:20:10
阅读次数:
118
题目地址:https://leetcode-cn.com/problems/merge-k-sorted-lists/ 解题思路:简单的分治算法 /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...
分类:
编程语言 时间:
2020-08-15 22:27:55
阅读次数:
64
// C++ #include<iostream> using namespace std; //链表的定义 struct ListNode { int val; ListNode* next; ListNode(int n) :val(n), next(nullptr) {} }; //链表的打印 ...
分类:
其他好文 时间:
2020-07-29 09:59:12
阅读次数:
68
206. 反转链表 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 递归 # Definition for singly-linked list. # class ListNode: # def __init__(self, ...
分类:
其他好文 时间:
2020-07-26 23:15:52
阅读次数:
76
考察链表的操作,合并两个有序链表,合并后的链表仍是有序的。 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* ne ...
分类:
编程语言 时间:
2020-07-26 01:33:46
阅读次数:
65
考察链表的操作,找到单向链表中环的入口节点 C++版 #include <iostream> #include <algorithm> using namespace std; // 定义链表 struct ListNode{ int val; struct ListNode* next; List ...
分类:
其他好文 时间:
2020-07-26 00:49:30
阅读次数:
60