笔试题
xqn2017
大家好,我是一名目前在上海工作的入门码农,写博客是为自己的学习过程做个记录,同时也希望能认识更多的IT爱好者一起探讨技术或者生活琐事,有希望认识的同学可以加我QQ:380191204
展开
-
【剑指offer】从尾到头翻转打印单链表
#include #include #include using namespace std;struct ListNode{ int m_Value; ListNode *next;};void ReversePrint(ListNode* pHead){ std::stack s; ListNode *pTemp = pHead; if(NULL == pHead)原创 2017-06-17 19:51:29 · 152 阅读 · 0 评论 -
【剑指offer】单链表尾部插入一个节点
#include using namespace std;//链表结构体struct ListNode{ int m_Value; ListNode *next;};//创建一个单链表ListNode *CreateList(int *a,int n){ ListNode *pHead = NULL; ListNode *pTemp = NULL; int i = 0原创 2017-06-15 09:50:44 · 856 阅读 · 0 评论 -
优酷土豆2012.9.12校园招聘会笔试题
给你一个由n-1个整数组成的未排序的序列,其元素都是1到n中的不同的整数。请写出一个寻找序列中缺失整数的线性时间算法。分析:只要通过异或算法就可实现,由于1^1=0,2^2=0,0^n = 0;因此,数组中的所有数据与1-n一起做异或,缺失的数据就会显现出来,代码如下所示:int getLostNum(int a[],int n){ int result = 0; int loo原创 2017-06-08 20:27:18 · 437 阅读 · 0 评论 -
Google 2013笔试题一
2.1 给定三个整数a,b,c,实现 int median(int a, int b, int c),返回三个数的中位数,不可使用sort,要求整数操作(比较,位运算,加减乘除等)次数尽量少,并分析说明程序最坏和平均情况下使用的操作次数。分析:中位数的意思是一个有序列中间的一个(奇数个数情况)或者中间两个的平均值(偶数个数情况)int median(int a,int b,原创 2017-06-08 20:54:32 · 181 阅读 · 0 评论 -
【剑指offer】将字符串中的空格替换成"%20"
思路:从后往前替换,先得到空格数和原字符串长度,计算得到目的字符串长度,然后逐个替换,只有碰到空格时才做特殊处理#include #include using namespace std;char *ReplaceSpace(char *str,int MaxLen){ int SpaceNum = 0; int srcIdx = 0; int srcLen = 0; int原创 2017-06-15 10:25:31 · 252 阅读 · 0 评论