目录:
1、题目及分析
1.1 题目
1.2 分析
1、题目及分析
1.1 题目:
Sort a linked list in O(n log n)
time using constant space complexity.
1.2 分析
O(n log n)的复杂度,所以不能采用冒泡等,这里采用合并排序算法,且为了不采用递归的方式,...
分类:
其他好文 时间:
2014-11-21 16:17:51
阅读次数:
138
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord...
分类:
其他好文 时间:
2014-11-21 06:57:04
阅读次数:
155
Sort a linked list inO(nlogn) time using constant space complexity.O(nlogn),我们可以第一时间想到常用的二路归并排序,快速排序和堆排序,其中快排和堆排只适用于线性表,即数组,故这道编程题毫无疑问用二路归并排序;* 1. 利用一...
分类:
其他好文 时间:
2014-11-19 07:24:33
阅读次数:
225
问题描述:
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of
O(log n).
If the target is not...
分类:
其他好文 时间:
2014-11-19 01:38:53
阅读次数:
229
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity...
分类:
其他好文 时间:
2014-11-18 23:06:47
阅读次数:
188
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution 1:PriorityQueue: 1 /** 2 * Definition for si....
分类:
其他好文 时间:
2014-11-17 08:04:09
阅读次数:
176
题目:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:我的第一个想法是将lists中的链表两两合并排序,这样时间复杂度是o(n),n为所有链表中的数据...
分类:
其他好文 时间:
2014-11-16 18:31:00
阅读次数:
209
Sort a linked list inO(nlogn) time using constant space complexity.分析:merge sort。class Solution {public: ListNode *sortList(ListNode *head) { ...
分类:
其他好文 时间:
2014-11-16 15:51:43
阅读次数:
210
Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
分类:
其他好文 时间:
2014-11-16 08:12:43
阅读次数:
145
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity...
分类:
其他好文 时间:
2014-11-15 11:18:50
阅读次数:
137