Sort a linked list in O(n log n) time using constant space complexity.merge sort、heap sort和quick sort都是O(nlgn),但是mergesort和quicksort都是递归的,不是constant s...
分类:
其他好文 时间:
2014-07-06 21:07:41
阅读次数:
210
它的思想是将一个无序的数组先用递归进行二分,当分解为无限小时,即为单个整数时,再对其进行排列。得出有序的数组 代码如下: package com.jll.sort; public class MergeSort { public MergeSort() { } public void merge(i...
分类:
其他好文 时间:
2014-07-06 21:01:33
阅读次数:
161
Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol...
分类:
其他好文 时间:
2014-07-06 19:31:04
阅读次数:
181
Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of ...
分类:
其他好文 时间:
2014-07-06 17:44:30
阅读次数:
181
Divide two integers without using multiplication, division and mod operator.思路:不能使用乘法除法以及取模运算来计算两个数相除。主要做法就是,将因子不断乘2(向左移位即可实现),同时结果从1不断移位加倍,等到除数大于被除数一...
分类:
其他好文 时间:
2014-07-06 15:34:24
阅读次数:
197
Divide two integers without using multiplication, division and mod operator.不用乘、除、求余操作,返回两整数相除的结果,结果也是整数。假设除数是2,相除的商就是被除数二进制表示向右移动一位。假设被除数是a,除数是b,因为不知...
分类:
其他好文 时间:
2014-07-05 20:37:18
阅读次数:
193
一,归并排序 归并排序是建立在归并操作上的一种排序算法,它采用了分治法的思想,是一种稳定的排序算法,而且归并排序的速度仅次于快速排序。时间复杂度:O(n*logn),最坏的情况:O(n*logn),空间复杂度:O(n)。从数据就可以看出:归并排序比快速排序快很多,同样为稳定排序。 ...
分类:
其他好文 时间:
2014-07-05 11:16:20
阅读次数:
208
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of...
分类:
其他好文 时间:
2014-07-04 07:35:58
阅读次数:
215
def IsContinuous(seq, num = 5):
zeros = 0; d = 0
seq = sorted(seq)
for i in range(num - 1):
if seq[i] == 0:
zeros += 1
continue
if seq[i] == seq[i + 1]:
return False
d += seq[i + 1]...
分类:
其他好文 时间:
2014-07-04 07:11:20
阅读次数:
171