Array
文章平均质量分 75
cool_bomb
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
从字符串中删除重复的字符
设计一个算法去移除字符串中重复的字符,但是只可以使用一个或两个变量的额外空间。 Design an algorithm and write code to remove the duplicate characters in astring without using any additional buffer. NOTE: One or two additional variables翻译 2013-02-15 02:01:43 · 1033 阅读 · 0 评论 -
判断数组的每行和每列是否由{a,b,c...z}这26个字符组成
给定数组A,大小为26*26.判断数组的每一行和每一列由{a,b,c...z}这26个字符组成,这些字符只出现一次。Given an array A of size 26*26. Determine whether each row and column of the array consists of set {a,b,c,d,.....z} where each element occ翻译 2013-05-11 17:18:23 · 806 阅读 · 0 评论 -
在函数中使用二维数组做参数
将一维数组声明为函数的形参,在函数的形参列表中,可以让数组的括号为空。例如,一个以一维数组为形参的函数原型可以用以下语句声明:void process1DArray(int[]);一个二维数组的行数(由二维数组的第一个下标指定)不是必需的,而列数(由第二个下标指定)是必需的。例如,以下这个函数原型声明表示函数有一个二维数组参数,其列数由整型常量SIZE指定:void process2D转载 2013-05-25 18:52:30 · 4932 阅读 · 1 评论 -
更新矩阵
给定一个矩阵,大小为n x m ,元素为0和1.例如下图:Given a matrix of size n x m filled with 0's and 1'se.g.:1 1 0 1 00 0 0 0 0 0 1 0 0 01 0 1 1 0如果矩阵在(i,j)处为1,将第i行和第j列用1填充。填充上图得到下图:if the matrix has 1 at翻译 2013-05-13 22:10:23 · 974 阅读 · 0 评论 -
以递增顺序打印2^i*5^j
以递增的顺序打印2^i*5^j这N个数组 所有的 i >= 0 , j >= 0Print N numbers of form 2^i.5^j in increasing order for all i >= 0 , j >= 0 ?Example : - 1,2,4,5,8,10,16,20.....#include #include void print(int翻译 2013-05-27 23:02:21 · 1083 阅读 · 0 评论 -
笔试题:环上货物均摊/糖果传递 解题报告
http://www.cnblogs.com/lyfruit/archive/2013/05/06/3063766.html昨天参加了2013年阿里巴巴实习生校园招聘的笔试。其中有一道题似曾相识,在快交卷的时候才隐约回想起这是一个数学问题。但具体怎么做的却想不起来了。为了避免再次遗忘,所以还是动手自己再写一写吧。题目参考:http://blog.youkuaiyun.com/hnmjiayou/a转载 2013-05-14 21:04:46 · 621 阅读 · 0 评论 -
将小顶堆转换为大顶堆
使用从元素下标HeapSize/2-1开始到0,使用MaxHeapify()函数重新建堆。void maxHeapify(int []A,int heapSize,int i){ int left = 2*i; int right = 2*i + 1; int larger = i; if (left A[larger]) { larger = left; } if (r原创 2013-05-15 17:05:16 · 1667 阅读 · 0 评论 -
找出数组中某个元素第一次出现的位置
Given a sorted array, write a function to search first occurrence of a number in the array. If not found return -1.Example::{2,2,2,3,4,5,5,6,6,8,9}search 6should return 7.给定一个排序的数组,找出数组中某个翻译 2013-06-02 13:08:15 · 10833 阅读 · 0 评论 -
【编程珠玑】空间换时间的数据结构问题
One problem with trading more space to use less time is that initializing the space can itself take a great deal of time. Show how to circumvent this problem by designing a technique to initialize an转载 2013-06-17 19:59:45 · 1711 阅读 · 0 评论 -
从4300000000个中找出重复的数
http://www.onlymarshall.com/2008/10/16/%E4%B8%80%E9%81%93%E7%BC%96%E7%A8%8B%E7%8F%A0%E7%8E%91%E7%9A%84%E9%A2%98%EF%BC%8C%E7%BB%88%E4%BA%8E%E6%90%9E%E6%87%82%E4%BA%86/给定一个包含4300000000个32位整数的顺序文件,请问转载 2013-06-18 16:19:19 · 1109 阅读 · 0 评论 -
以旋转的方式输出一个矩阵中的元素
给定一个矩阵,有m行,n列。按照顺时针的顺序输出他的各个元素。可以通过设置四个方向变量up down left right 不断的变化这些方向变量来输出元素。初始化时up = 0,down = m-1; left = 0,right = n-1;首先输出矩阵中第up行的第left列到第right-1列的元素然后输出第right 列 的 第原创 2013-05-24 21:12:13 · 2069 阅读 · 0 评论 -
找出滑动窗口数组中的最大值
给定大小为N的数组。数组被分为大小为k的子数组。找到每个子数组的最大值。子数组为滑动窗口。如果数组为1 2 3 4 5 6子数组为1 2. 2 3. 3 4. 4 5. 5 6.An array of size N is given. Array is sub divided into sub array of size K. Find maximum value of翻译 2013-05-21 14:25:12 · 3831 阅读 · 0 评论 -
在部分递增和部分递减的数组中查找某个元素
给定一个整数数组,它的前一部分严格的递增,后一部分严格递减。从数组中搜索某个元素。Given an array of integers having the property that first that array is strictly increasing then it is strictly decreasing, You have to search for a given翻译 2013-05-16 22:49:42 · 2117 阅读 · 0 评论 -
数组元素交叉排列的算法题(a1 a2 a3 .. an b1 b2 b3 .. bn -->a 1 b1, a2 b2, a3 b3, .. an bn )
题目:给定整数数组,元素为a1 a2 a3 .. an b1 b2 b3 .. bn元素个数为 2n要求:请生成如下数组,a1 b1, a2 b2, a3 b3, .. an bn. 条件:时间复杂度为O(N),空间复杂度为O(1).来源:http://topic.youkuaiyun.com/u/20100623/09/dd25166f-bac4-4b2d-98ab-71cab69f转载 2013-02-14 00:51:45 · 991 阅读 · 0 评论 -
改进的筛素数法
http://blog.youkuaiyun.com/morewindows/article/details/7347459最简单的筛素数法方法就是从2开始,将所以2的倍数去掉,然后从3开始,将3的倍数去掉。根据这样很容易写出代码,下面代码就是是筛素数法得到100以内的素数并保存到primes[]数组中。[cpp] view plaincopy//b转载 2013-02-15 22:23:06 · 509 阅读 · 0 评论 -
在给定的数组中找出两个元素和为给定值的所有元素对
Design an algorithm to find all pairs of integers within an array which sum toa specified value. 使用hash map:1假设V为给定的值,A为给定的数组。2创建hash map M,M将从数组元素映射到出现次数。3对数组中的元素A[i]:如果 V-A[i] 在M中,翻译 2013-02-16 23:15:16 · 1847 阅读 · 1 评论 -
找出数组中缺失的数
从数组0到n之间的整数拿掉一个,其余的数为数组A[1...n]的元素。由于A的元素以bit表示,所以不能一次获得A的整个元素。唯一能做的是取得A[i]的第j个bit。An array A[1...n] contains all the integers from 0 to n except for one numberwhich is missing. In this proble翻译 2013-02-17 01:16:25 · 2608 阅读 · 0 评论 -
把数组排成最小的数
http://zhedahht.blog.163.com/blog/#m=0题目:输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个。例如输入数组{32, 321},则输出这两个能排成的最小数字32132。请给出解决问题的算法,并证明该算法。分析:这是09年6月份百度新鲜出炉的一道面试题,从这道题我们可以看出百度对应聘者在算法方面有很高的要求。这道题其转载 2013-03-03 14:26:05 · 532 阅读 · 0 评论 -
数对之差的最大值
http://zhedahht.blog.163.com/题目:在数组中,数字减去它右边的数字得到一个数对之差。求所有数对之差的最大值。例如在数组{2, 4, 1, 16, 7, 5, 11, 9}中,数对之差的最大值是11,是16减去5的结果。分析:看到这个题目,很多人的第一反应是找到这个数组的最大值和最小值,然后觉得最大值减去最小值就是最终的结果。这种思路忽略了题目中很重要的一点:转载 2013-03-03 20:08:20 · 414 阅读 · 0 评论 -
求字符串中包含唯一字符的最长子串
给你一个字符串,找到只包含唯一字符的最长子串。Given a string, find the longest sub sequence which contains only unique characters.维护两个指针,左指针和右指针。同时用一个hash表存储左右指针之间的字符以及字符出现的位置。初始化的时候:left = 0,right = 0.右指针不断的前移,同时将所指的翻译 2013-03-14 21:31:49 · 1919 阅读 · 0 评论 -
找出数组中下一个大数
给出一整数数组,找出比当前元素大的下一个数。Array on integer is givenfind out next bigger number Ex {2,5,3,4,6,1}Out: 2->55->63->44->66->-1 //not possible1-> -1 //not possible算法时间和空间复杂度都为O(n)翻译 2013-03-16 20:29:09 · 968 阅读 · 0 评论 -
找出面积最大的土地
假设有二维数组元素为L W L表示土地,W表示水域,使用DP找到面积最大的土地,每个单元的土地被视为1个单位,只能考查一块土地的上下左右的连续单元,不能考查斜线方向的。Example:LLLLLLWLLWLWWWLL上图答案为8.Suppose you have given a 2D array having filled with "L" or "W" i.e翻译 2013-05-16 17:09:12 · 1269 阅读 · 0 评论 -
找出数组中出现次数最多的子串
给定int数组一个,找出出现次数最多的非空子串。如果有多个这种子串,返回最长的子串。两个子串如果包含完全相同的字符,且字符顺序也相同,那么他们相等。Given an array of ints, find the most frequent non-empty subarray in it. If there are more than one such sub-arrays re翻译 2013-07-01 22:59:31 · 1489 阅读 · 0 评论
分享