码迷,mamicode.com
首页 >  
搜索关键字:排序数组    ( 1092个结果
leetcode题解:Search for a Range (已排序数组范围查找)
题目: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-16 19:48:18    阅读次数:263
编程算法 - 和为s的两个数字 代码(C)
和为s的两个数字 代码(C)本文地址: http://blog.csdn.net/caroline_wendy题目: 输入一个递增排序的数组和一个数字s, 在数组中查找两个数, 使得它们的和正好是s.如果有多对数字的和等于s, 输出任意一对即可.排序数组, 则可以从两端开始进行查找, 当和大于时, 则减少前端, 当和小于时, 则递增尾端.代码:/* * main.cpp * * Creat...
分类:其他好文   时间:2014-07-12 21:15:56    阅读次数:206
leetcode 题解:Merge Sorted Array(两个已排序数组归并)
题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or eq...
分类:其他好文   时间:2014-07-10 14:41:23    阅读次数:177
sort函数用法
头文件: #include using namespace std; 1.默认的sort函数是按升序排序。  sort(a,a+n);                //两个参数分别为待排序数组的首地址和尾地址 2.可以自己写一个cmp函数,按特定意图进行排序。 例如 : 1).对数组a降序排序 int cmp( const int &a, const int &b ){...
分类:其他好文   时间:2014-07-08 20:11:02    阅读次数:172
leetcode 题解:Search in Rotated Sorted Array II (旋转已排序数组查找2)
题目:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function...
分类:其他好文   时间:2014-07-07 00:14:37    阅读次数:186
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 target valu...
分类:其他好文   时间:2014-07-06 23:34:53    阅读次数:273
编程算法 - 数字在排序数组中出现的次数 代码(C)
数字在排序数组中出现的次数 代码(C)本文地址: http://blog.csdn.net/caroline_wendy题目: 统计一个数字在排序数组中出现的次数.通过折半查找, 找到首次出现的位置, 再找到末次出现的位置, 相减即可.时间复杂度O(logn).代码:/* * main.cpp * * Created on: 2014.6.12 * Author: Spike ...
分类:其他好文   时间:2014-07-06 09:45:25    阅读次数:177
leetcode 题解:Remove Duplicates from Sorted Array(已排序数组去重)
题目:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space fo...
分类:其他好文   时间:2014-07-03 20:58:08    阅读次数:248
leetcode 题解:Remove Duplicates from Sorted Array II(已排序数组去三次及以上重复元素)
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should ...
分类:其他好文   时间:2014-07-03 12:10:12    阅读次数:191
leetcode——Search for a Range 排序数组中寻找目标下标范围(AC)
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 found ...
分类:其他好文   时间:2014-06-22 21:47:15    阅读次数:269
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!