随笔分类 -  sort

快速排序之单项扫描法
摘要:快速排序是排序算法中最受青睐的算法之一,相对于堆排序和归并排序而言,即便具有相同的复杂度O(NlogN)。面对大数据而言,快排的效率也更高。一般而言,数据结构中的排序算法都是采取的双向指针法。在之前写的一篇博文《排序算法(初级版)之快排、归并、堆排序》中已经有过总结。这里就不再啰嗦了。本篇博文主要讲... 阅读全文

posted @ 2014-08-22 17:00 喵星人与汪星人 阅读(1785) 评论(0) 推荐(0) 编辑

[leetcode]Sort Colors
摘要:Sort ColorsGiven an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the or... 阅读全文

posted @ 2014-08-11 21:48 喵星人与汪星人 阅读(253) 评论(0) 推荐(0) 编辑

[leetcode]Search a 2D Matrix
摘要:Search a 2D MatrixWrite an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row... 阅读全文

posted @ 2014-08-11 20:07 喵星人与汪星人 阅读(133) 评论(0) 推荐(0) 编辑

[leetcode]First Missing Positive
摘要:First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Yo... 阅读全文

posted @ 2014-08-09 22:32 喵星人与汪星人 阅读(167) 评论(0) 推荐(0) 编辑

[leetcode]Median of Two Sorted Arrays
摘要:Median of Two Sorted ArraysThere are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run... 阅读全文

posted @ 2014-08-08 15:13 喵星人与汪星人 阅读(233) 评论(0) 推荐(0) 编辑

[leetcode]Longest Consecutive Sequence
摘要:Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4... 阅读全文

posted @ 2014-08-07 16:23 喵星人与汪星人 阅读(185) 评论(0) 推荐(0) 编辑

排序算法(初级版)之快排、归并、堆排序
摘要:排序算法是算法中的基础,也是面试常问常考的算法之一,今天先简单整理一下最常考的三个排序算法。以后有空(希望有空)了再统一优化一下。七大排序算法的复杂度分析排序算法最坏时间辅助度平均时间复杂度空间复杂度稳定性备注冒泡排序 O(n^2) O(n^2) O(1)YES交换排序 O(n^2) O(... 阅读全文

posted @ 2014-08-06 23:49 喵星人与汪星人 阅读(340) 评论(0) 推荐(0) 编辑

[leetcode]Candy
摘要:CandyThere areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following ... 阅读全文

posted @ 2014-08-04 23:59 喵星人与汪星人 阅读(181) 评论(0) 推荐(0) 编辑

[leetcode]Anagrams
摘要:AnagramsGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.编程珠玑中的一道题,书中的解法很巧妙,我就直接搬来用了,时... 阅读全文

posted @ 2014-08-01 19:56 喵星人与汪星人 阅读(359) 评论(0) 推荐(0) 编辑

[leetcode]Recover Binary Search Tree
摘要:Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A sol... 阅读全文

posted @ 2014-07-31 19:47 喵星人与汪星人 阅读(236) 评论(0) 推荐(0) 编辑

[leetcode]Validate Binary Search Tree
摘要:Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtre... 阅读全文

posted @ 2014-07-31 19:39 喵星人与汪星人 阅读(188) 评论(0) 推荐(0) 编辑

[leetcode]Subsets II
摘要:Subsets IIGiven a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descend... 阅读全文

posted @ 2014-07-25 22:57 喵星人与汪星人 阅读(254) 评论(0) 推荐(0) 编辑

[leetcode]Insert Interval
摘要:Insert IntervalGiven a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals... 阅读全文

posted @ 2014-07-25 22:16 喵星人与汪星人 阅读(172) 评论(0) 推荐(0) 编辑

[leetcode]Merge Sorted Array
摘要:Merge Sorted ArrayGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that i... 阅读全文

posted @ 2014-07-24 22:52 喵星人与汪星人 阅读(221) 评论(0) 推荐(0) 编辑

[leetcode]Next Permutation
摘要:Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangemen... 阅读全文

posted @ 2014-07-23 18:41 喵星人与汪星人 阅读(262) 评论(0) 推荐(0) 编辑