10 2013 档案

摘要:题目:定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。要求函数min、push以及pop的时间复杂度都是O(1)。#include#include#define M 100#define m 10struct minStack{int top;int tail;int *valueStack;int *indexStack;};void InitStack(minStack& s){s.top = 0;s.tail = 0;s.valueStack = (int*)malloc(sizeof(int)*M);s.indexStack = (int*)malloc(siz 阅读全文
posted @ 2013-10-31 19:27 idealing 阅读(266) 评论(0) 推荐(0)
摘要:题目:输入一个整形数组,数组里有正数也有负数。数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。求所有子数组的和的最大值。要求时间复杂度为O(n)。Case1:输入数组:1,-2,3,10,-4,7,2,-5 和最大连续子数组为3,10,-4,7,2 则输出18Case2:输入数组:3,-2,3,10,-4,7,2,-5 和最大连续子数组为3,-2,3,10,-4,7,2 则输出19程序写的比较简单,看了网上的知道自己的缺陷:没有考虑输入为空与和最大为0的区别。。。 #include #include void InitArray(int*& A,int M){ ... 阅读全文
posted @ 2013-10-30 20:30 idealing 阅读(284) 评论(0) 推荐(0)
摘要:题目的要求如上图所示测试用例(先构造二叉查找树)void buildBSTreeNode(BSTreeNode* head,int data){node = (BSTreeNode*)malloc(sizeof(BSTreeNode));node->data = data;node->m_Left = NULL;node->m_Right = NULL;BSTreeNode* p = head;while(p){ if(node->data > p->data){ if(!p->m_Right){ p->m_Right = node; ... 阅读全文
posted @ 2013-10-26 23:49 idealing 阅读(225) 评论(0) 推荐(0)
摘要:题目的要求很简单,就是输出这样一个蛇形矩阵。。。这道题是在面试亚马逊实习生时遇到的,当初的思路是针对每行元素的增加个数来编程,不过现在来想,按照每行元素增加的话要考虑的因素就太多了,不如这样以元素坐标来思考,来的简单明了。下面以4阶矩阵为例:由上图可得规律:①坐标之和i + j = k - 1;②k为奇数时,i为减,j为增;偶数时,i为增,j为减;③当k n 时,元素坐标以n - 1为起点递减(相应另一坐标递增),元素个数递减;比较难实现的是体现k > n 时的情况,用两个变量完成,一个累计每行元素个数,一个表示元素坐标(当然还有k表示行,count表示元素总个数)#include#in 阅读全文
posted @ 2013-10-20 22:11 idealing 阅读(982) 评论(0) 推荐(0)
摘要:Let's assume that there is a simple market for beans. Every day there is a published bean price in the market. Traders can buy or sell at the published price. There is a trader who time travelled to future and brought back the price information for a number of days in the future. If you have thi 阅读全文
posted @ 2013-10-16 20:23 idealing 阅读(317) 评论(0) 推荐(0)