桶排序,计数排序,基数排序

桶排序: 要排序的数据有n个,均匀地划分到m个桶内,每个桶里就有k=n/m个元素。每个桶内部使用快速排序,时间复杂度为O(k*logk)。m个桶排序的时间复杂度是O(m*k*logk),因为k=n/m,所以整个桶排序的时间复杂度就是O(n*log(n/m))。当桶个数m接近数据个数n时,log(...

2018-10-22 08:29:00

阅读数:37

评论数:0

Reverse Pairs

Given an array nums, we call (i, j) an important reverse pair if i < j and nums[i] > 2*nums[j].You need to return the number of...

2018-06-26 09:42:28

阅读数:19

评论数:0

Count of Smaller Numbers After Self

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i]is the number of smal...

2018-06-26 09:11:55

阅读数:21

评论数:0

数组中的逆序对

int InversePairsCore(int* data, int* copy, int start, int end); int InversePairs(int* data, int length) { if(data == nullptr || length &...

2018-06-26 08:05:24

阅读数:52

评论数:0

归并排序

void Merge(int *nums,int left,int mid,int right) { int n1=mid-left+1; int n2=right-mid; int *nums1=(int *)malloc(sizeof(int )*n1); in...

2018-06-26 08:00:08

阅读数:34

评论数:0

Kth Largest Element in an Array(快速排序和堆排序方法解决)

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example ...

2018-06-25 10:06:59

阅读数:28

评论数:0

KMP排序

Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack ...

2018-06-25 09:08:27

阅读数:16

评论数:0

字符的左右移动

给定一个字符串,这个字符串为*号和26个字母的任意组合。现在需要把字符串的*号都移动到最左侧,而把字符串中的字母移动到最右侧并保持相对顺序不变,要求时间复杂度和空间复杂度最小。 void switcher1(char str[]) { int len=strlen(str); ...

2018-06-07 08:38:43

阅读数:68

评论数:0

快速排序

#include<iostream> using namespace std; void quickSort(int a[],int,int); int main() { int array[]={34,65,12,43,67,5,78,10,3,70...

2018-03-10 19:09:59

阅读数:53

评论数:0

148. Sort List

Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; ...

2018-03-06 08:17:34

阅读数:31

评论数:0

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.Example:...

2018-03-01 21:20:42

阅读数:42

评论数:0

617. Merge Two Binary Trees

  Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others a...

2018-02-05 08:55:44

阅读数:47

评论数:0

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...

2018-01-22 08:21:55

阅读数:51

评论数:0

堆排序

#include #include #include using na...

2018-01-09 13:10:52

阅读数:98

评论数:0

提示
确定要删除当前文章?
取消 删除
关闭
关闭