![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
剑值offer
happy曾帅
这个作者很懒,什么都没留下…
展开
-
剑值offer(面试题目64)数据流中的中位数
#include #include #include using namespace std; void PrintfVectorInt(vector &vet) { for (vector::iterator pos = vet.begin(); pos != vet.end(); pos++) cout<<*pos<<" "; } template class Dynamic_Ar原创 2015-01-24 11:18:20 · 1131 阅读 · 0 评论 -
面试题目65(滑动窗口的最大值)
题目:给定一个数组和滑动窗口的大小,请找出所有滑动窗口的最大值,例如如果输入数组是 {2,1,3,2,6,2,5,1},则滑动窗口的最大值是{3,3#include #include #include using namespace std; vector max_windows(const vector &num,unsigned int size) { vector max_num; d原创 2015-01-24 15:44:52 · 648 阅读 · 0 评论 -
面试题目67(机器人的运动范围)
题目:地上有一个M行N列的方格,一个机器人从坐标(0,0)的格子开始移动,它每一次可以向上下左右移动一格 ,但不能进入行坐标和列坐标的数位之和大于k的格子,例如当k为18时,机器人能够进入方格(35,37),因为3+5+7+3=18 #include using namespace std; int getdigitsum(int number) { int sum=0; while(nu原创 2015-01-24 20:23:38 · 751 阅读 · 0 评论 -
面试题目66(矩阵中的路径)
题目:请设计一个函数,用来判断在一个矩阵中是否存在一条包含某路径 字符串所有字符的路径,路径可以从矩阵中任意一格开始,每一步可以在矩阵中向左右上下移动一格, #include using namespace std; //判断矩阵中是否存在相应的路径 bool has_path_core(char *matrix,int rows,int cols,int row,int col,char *原创 2015-01-24 16:47:54 · 858 阅读 · 0 评论 -
剑指offer24判断某一序列是否是某一搜索二叉树的后续遍历结果
#include using namespace std; bool verify(int A[],int length) { if(A==NULL||length<=0) return false; int root=A[length-1]; int i=0; for(;i<length;++i) { if(A[i]>A[root]) break; } int j=i原创 2015-03-24 11:32:59 · 522 阅读 · 0 评论 -
剑指offer中找出出现次数超过一半的数字
#include #include using namespace std; bool check(int *numbers,int length,int number) { int times=0; for(int i=0;i<length;++i) { if(numbers[i]==number) times++; } bool ismorethanhalf=true;原创 2015-04-02 10:34:16 · 511 阅读 · 0 评论 -
剑指offer统计字符数组中第一次出现的字符
给定一个字符串,例如“abaccdeff”则第一次出现的字符就是b; #include #include using namespace std; void first(const string &input) { if(input.empty()) return ; string::size_type length=input.size(); int *times=new int[l原创 2015-04-03 11:08:37 · 449 阅读 · 0 评论 -
剑指offer中在一个有序数组中找出和为s的两个数字
#include using namespace std; bool findnumberwithsum(int A[],int length,int *num1,int *num2,int key) { if(NULL==A||length return false; int start=0; int end=length-1; int sum=0; while(start原创 2015-04-10 09:24:10 · 668 阅读 · 1 评论 -
用栈的知识实现四则运算(带括号的加减乘除)
#include #include #include #include using namespace std; void size_yunsuan(string input,string &a) { int i=0; int length=input.size(); stack stack1; while(i<length) { //cout<<input[i]<<endl;原创 2015-04-12 10:20:06 · 3410 阅读 · 0 评论