leetcode排序
葱shen
爱技术,爱学习,爱游戏~
展开
-
[leetcode] 【排序】 88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-06-20 11:56:10 · 185 阅读 · 0 评论 -
[leetcode] 【排序】 21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 题意 合并两个链表,新的链表由两个链表的节点组成。 题解 和归并类似,一步步取两条链最小那个节点即可。原创 2016-06-20 12:11:19 · 220 阅读 · 0 评论 -
[leetcode] 【排序】 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题意 合并k个排好序的链表,并返回这个排好序的链表。 题解 两个两个合并,即复用[leetcode] 【排序】 21. Merge Two Sorted Lists这题的函数。 /**原创 2016-06-20 12:46:13 · 242 阅读 · 0 评论 -
[leetcode] 【排序】 147. Insertion Sort List
Sort a linked list using insertion sort. 题意 用插入排序算法为链表排序。 题解 遍历原链表的每个元素,每个元素都有在新链表中从头往后找适合其的位置,然后插入。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode原创 2016-06-20 13:00:07 · 221 阅读 · 0 评论 -
[leetcode] 【排序】 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity. 题意 对链表进行排序,时间复杂度O(n log n),空间复杂度为常数。 题解 可原创 2016-06-20 13:20:20 · 185 阅读 · 0 评论 -
[leetcode] 【排序】 41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant原创 2016-06-20 18:12:18 · 228 阅读 · 0 评论 -
[leetcode] 【排序】 75. Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers原创 2016-06-20 19:00:36 · 215 阅读 · 0 评论