Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
分类:
编程语言 时间:
2014-07-22 00:39:35
阅读次数:
263
My first reaction: move all A elements back by n positions, and start everything from A[0] and B[0]. But a smarter idea is to start everything from th...
分类:
其他好文 时间:
2014-07-22 00:35:36
阅读次数:
189
冒泡排序代码:
#include
#include
using namespace std;
template
void bubbleSort(ItemType theArray[], int n)
{
bool sorted = false; // False when swaps occur
int pass = 1;
while (!sorted && (pass...
分类:
其他好文 时间:
2014-07-22 00:32:35
阅读次数:
363
题目: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....
分类:
编程语言 时间:
2014-07-21 11:14:07
阅读次数:
203
Simply care about the boundary cases:class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { if (l1 && !l2) return l1;...
分类:
其他好文 时间:
2014-07-21 11:07:04
阅读次数:
206
Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
分类:
其他好文 时间:
2014-07-21 09:08:29
阅读次数:
209
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; ...
分类:
其他好文 时间:
2014-07-21 00:11:12
阅读次数:
254
inplace_merge(应用于有序区间)
--------------------------------------------------------------------
描述:如果两个连接在一起的序列[first, middle)和 [middle, last]都已排序,
那么 inplace_merge 可将它们结合成单一一个序列,并仍有序。
源码:
template
inline void inplace_merge(Bidi...
分类:
其他好文 时间:
2014-07-20 23:27:42
阅读次数:
368
题目链接:
啊哈哈,选我
题目:
Sorting It All Out
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 26897
Accepted: 9281
Description
An ascending sorted s...
分类:
其他好文 时间:
2014-07-20 23:22:58
阅读次数:
301
merge sort
----------------------------------------------------------------------
描述:归并排序
思路:
1.将区间对半分割
2.对左、右段分别排序
3.利用inplace_merge将左、右段合并成为一个完整的有序序列
复杂度:O(log n)
源码:
template
void mergesort(BidirectionalIter first, Bidirecti...
分类:
其他好文 时间:
2014-07-20 23:05:52
阅读次数:
245