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
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-07-22 00:35:34
阅读次数:
238
冒泡排序代码:
#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
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target ....
分类:
编程语言 时间:
2014-07-21 14:37:05
阅读次数:
266
Blurs an image using the median filter.C++: void medianBlur(InputArray src, OutputArray dst, int ksize)Python: cv2.medianBlur(src, ksize[, dst]) → dstParameters:src – input 1-, 3-, or 4-channel image;...
分类:
编程语言 时间:
2014-07-21 13:37:14
阅读次数:
2184
题目: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
题目链接:
啊哈哈,选我
题目:
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
nth_element
------------------------------------------------------------------------------
描述:重新排序,使得[nth,last)内没有任何一个元素小于[first,nth)内的元素,
但对于[first,nth)和[nth,last)两个子区间内的元素次序则无任何保证。
思路:
1.以 median-of-3-partition 将整个序列分割为更小的左、右子序列
2.如果 nth 迭代器落于左序列,就再对左子...
分类:
其他好文 时间:
2014-07-20 23:20:34
阅读次数:
279