问题描述:
给一个数组,并且数组里面元素的值只可能是0,1,2,然后现在把这个数组排序。
另外一种表述: 现有n个红白蓝三种不同颜色的小球,乱序排列在一起,请通过两两交换任意两个球,使得从左至右,依次是一些红球、一些白球、一些蓝球。
解题思路:
采用快速排序partition的思想,用两个指针将三种颜色间隔开。
下面引用此处内容 July 编程艺术系列中荷兰国旗问题。
一个...
分类:
编程语言 时间:
2015-06-08 09:45:17
阅读次数:
213
实现赋值运算符重载函数,确保:
新的数据可准确地被复制旧的数据可准确地删除/释放可进行 A = B = C 赋值
class Solution {
public:
char *m_pData;
Solution() {
this->m_pData = NULL;
}
Solution(char *pData) {
th...
分类:
其他好文 时间:
2015-06-08 01:07:46
阅读次数:
142
lintcode 1: Data Stream Median
python java c++...
分类:
其他好文 时间:
2015-06-06 16:38:45
阅读次数:
136
Minimum Adjustment CostGiven an integer array, adjust each integers so that the difference of every adjacent integers are not greater than a given num...
分类:
其他好文 时间:
2015-06-03 13:19:07
阅读次数:
145
http://www.lintcode.com/en/problem/remove-node-in-binary-search-tree/# Given a root ofBINARY Search Tree with unique value for each node. Remove the n...
分类:
其他好文 时间:
2015-06-01 18:46:58
阅读次数:
87
Subarray SumGiven an integer array, find a subarray where the sum of numbers iszero. Your code should return the index of the first number and the ind...
分类:
其他好文 时间:
2015-06-01 13:00:46
阅读次数:
92
问题描述在一个无序的数组中,如果对其进行排序,然后扫描一遍有序数组,可以获得相邻两元素的最大差值,比如 {-1, 2, 4, 9},那么最大差值就是4和9之间,是5.
现在如果不对原始数组进行排序,有什么好的方案,来获取有序形式下的最大差值?
Given an unsorted array, find the maximum difference between the successive...
分类:
其他好文 时间:
2015-05-31 16:53:29
阅读次数:
109
给定一个数,怎么样不用系统函数sqrt,可以求得它的平方根的答案。...
分类:
编程语言 时间:
2015-05-29 09:59:23
阅读次数:
187
九章算法官网-原文网址http://www.jiuzhang.com/problem/71/题目给定一个有n个对象(包括k种不同的颜色,并按照1到k进行编号)的数组,将对象进行分类使相同颜色的对象相邻,并按照1,2,...k的顺序进行排序。在线测试本题http://www.lintcode.com/...
分类:
编程语言 时间:
2015-05-29 06:11:17
阅读次数:
504