![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
文章平均质量分 54
唐辰砂
编程之久除了算法和数据结构,什么也不属于我们
展开
-
【leetcode】Sort List
Sort a linked list in O(n log n) time using constant space complexity.题目要求:对一个链表进行归并排序。基本思想:1:利用归并排序的整体思想2:找到一个链表的中间节点的方法3:合并两个已排好序的链表为一个新的有序链表/** * Definition for singly-l原创 2015-06-04 10:03:08 · 395 阅读 · 0 评论 -
【leetcode】Insertion Sort List
Sort a linked list using insertion sort.建立一个新头结点,然后依次将head链表中的结点有序的插入到新链表中/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode原创 2015-06-04 13:58:13 · 404 阅读 · 0 评论 -
【leetcode】3sums
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2015-06-05 10:59:23 · 899 阅读 · 0 评论 -
【leetcode】Linked List Cycle II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *///两个指针slow和fast,都从链表头开始走,s每次走一步,f原创 2015-06-05 14:45:36 · 589 阅读 · 0 评论 -
【leetcode】Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as原创 2015-06-05 10:16:20 · 1584 阅读 · 1 评论 -
【leetcode】Linked List Cycle
//两个指针slow和fast,都从链表头开始走,s每次走一步,f每次走两步,等两个指针重合时,就说明有环,否则没有/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x)原创 2015-06-05 14:53:18 · 708 阅读 · 0 评论 -
【leetcode】Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to原创 2015-06-05 14:14:13 · 456 阅读 · 0 评论 -
【leetcode】Binary Tree Preorder Traversal
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };原创 2015-06-05 11:15:44 · 442 阅读 · 0 评论