码迷,mamicode.com
首页 >  
搜索关键字:sorted    ( 5925个结果
Python中字典排序
如字典dic={'a':1,'f':2,'c':3,'h':0};要对其进行排序:函数原型:sorted(dic,value,reverse);dic为比较函数;value为比较对象(键或值);reverse:注明升序还是降序,True--降序,False--升序(默认); 1 import ope...
分类:编程语言   时间:2014-11-11 20:30:30    阅读次数:346
两个排序数组求中位数
# 题目 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). # 思路 1. 丢掉一个最小的,...
分类:编程语言   时间:2014-11-11 19:26:00    阅读次数:285
LeetCode:Median of Two Sorted Arrays
题目描述: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 思路:写一个找两个数组中第k大数的函数,...
分类:其他好文   时间:2014-11-11 12:45:34    阅读次数:205
Find Minimum in Rotated Sorted Array 旋转数组中找最小值 @LeetCode
O(n)的算法就不说了,这题主要考查的是 O(logn)的算法。有序数组容易想到使用二分查找解决,这题就是在二分基础上做一些调整。数组只有一次翻转,可以知道原有序递增数组被分成两部分,这俩部分都是有序递增的(这题只需要考虑有序数组的递增情况)。假如翻转后的数组以第 x 个结点分为两部分 A[0..x] 和 A[x+1..n]。则 A[0..x] 这一段是有序递增的, A[x+1..m] 这一段也是...
分类:编程语言   时间:2014-11-11 12:44:02    阅读次数:261
Find Minimum in Rotated Sorted Array II 旋转数组中找最小值(有重复元素) @LeetCode
递归public class Solution { public int findMin(int[] num) { return helper(num, 0, num.length-1); } //with duplicate public static int helper(int[] a, int left, int right){ ...
分类:编程语言   时间:2014-11-11 12:40:09    阅读次数:211
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new lengt...
分类:其他好文   时间:2014-11-11 12:22:39    阅读次数:144
[Leetcode] Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ...
分类:其他好文   时间:2014-11-10 17:15:00    阅读次数:173
leetcode-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. 递归版 /** * Definition for singly-linked list. ...
分类:其他好文   时间:2014-11-10 13:55:03    阅读次数:195
LeetCode-Search in Rotated Sorted Array
题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2). You are given a targe...
分类:其他好文   时间:2014-11-10 13:41:57    阅读次数:203
[LeetCode]Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. /** * Definition for sin...
分类:其他好文   时间:2014-11-10 10:07:22    阅读次数:156
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!