LeetCode
一个人的世界中
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
6b.LeetCode.23.Merge k Sorted Lists【K个排序链表归并】
K个排序链表归并【23】(hard) #include <iostream> #include <algorithm> #include <vector> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; bool cmp(const ListNode *a, const Lis原创 2020-08-12 07:59:51 · 180 阅读 · 0 评论 -
6a.LeetCode.21.Merge Two Sorted Lists【2个排序链表归并】
2个排序链表归并【21】(easy) #include <iostream> using namespace std; struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {原创 2020-08-11 10:25:35 · 158 阅读 · 0 评论 -
5.LeetCode.138. Copy List with Random Pointer【复杂链表的复制】
复杂链表的复制【138】(medium) #include <iostream> #include <map> #include <vector> using namespace std; class Node { public: int val; Node *next; Node *random; Node(int _val) { val = _val; next = NULL;原创 2020-08-11 10:22:34 · 174 阅读 · 0 评论 -
4.LeetCode.86. Partition List【链表划分】
链表划分【86】(medium) #include <iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode *partition(ListNode *head, int x) { ListNode原创 2020-08-11 10:20:10 · 119 阅读 · 0 评论 -
3.LeetCode.142. Linked List Cycle II【链表求环】
链表求环【142】(medium) #include <iostream> #include <set> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode *detectCycle(ListNode *head) {原创 2020-08-11 10:18:02 · 122 阅读 · 0 评论 -
2.LeetCode.160.Intersection of Two Linked Lists【链表求交点】
链表求交点 【160】(easy) #include <iostream> #include <set> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; int get_list_length(ListNode *head) { int len = 0; while (head原创 2020-08-11 10:14:27 · 123 阅读 · 0 评论 -
1b.LeetCode.92.Reverse Linked List II【链表逆序2】
1-b. 链表逆序2 【92】(medium) #include <iostream> using namespace std; /* Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4-&原创 2020-08-11 10:08:09 · 155 阅读 · 0 评论 -
1a.LeetCode.206.reverse-linked-list【链表逆序】
1-a. 链表逆序 【206】(easy) #include <stdio.h> struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode *reverseList(ListNode *head) { // 方法一、双指针迭代 ListNode *原创 2020-08-11 10:01:52 · 121 阅读 · 0 评论
分享