笔试面试题
文章平均质量分 62
为了明年找到更好啊的工作,现在开始刷题,我刷的全部都是一些大公司的笔试面试题,希望对你们有所帮助
poison_biti
这个作者很懒,什么都没留下…
展开
-
详述大端小端存储
大端模式,是指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中,这样的存储模式有点儿类似于把数据当作字符串顺序处理:地址由小向大增加,而数据从高位往低位放;这和我们的阅读习惯一致。小端模式,是指数据的高字节保存在内存的高地址中,而数据的低字节保存在内存的低地址中,这种存储模式将地址的高低和数据位权有效地结合起来,高地址部分权值高,低地址部分权值低。原创 2016-07-22 23:31:44 · 444 阅读 · 0 评论 -
小米面试题——并查集(关于朋友圈问题)
假如已知有n个人和m对好友关系(存于数字r)。如果两个人是直接或间接的好友(好友的好友的好友...),则认为他们属于同一个朋友圈,请写出程序求出这n个人里一共有多少朋友圈。 例如:n=5,m=3,r={{1,2},{2,3},{4,5}},表示有5个人,1和2是好友,2和3是好友,4和5是好友。则1,2,3属于一个朋友圈,4,5属于另一个朋友圈,结果为两个朋友圈在处理这道题的时原创 2016-08-02 19:29:11 · 1173 阅读 · 0 评论 -
剑指offer——查找一个字符串中第一次出现一次的字符(哈希直接定址法)
哈希表——直接定址法的应用哈希表(Hash table,也叫散列表),是根据关键码值而直接进行访问的数据结构。也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。直接定址法——取关键字的某个线性函数为散列地址,Hash(key)=key或者Hash(key)=A*key+B,A和B是两个常数。剑指offer面试题:查找一个字符串中第一次出现一次的字符原创 2016-08-18 13:57:57 · 962 阅读 · 0 评论 -
面试题——不用循环计算1+2+...+100之和
前几天看到校招的面试题,要求不要用循环计算出1+2+3...+100之和。当我看到这道题的时候第一反应就是用递归写,能用循环的程序不一定能用递归去写,但是能用递归的程序一定可以用循环写出。所以递归和循环是相铺相成的。 这里我也不知道递归是不是面试考官想要的最优写法,但是这题至少没用循环。这里我写完后修改了下代码,不仅仅是只计算1+2+3...+100的程序,输入一个最小的数字(如5原创 2016-09-28 14:51:35 · 2066 阅读 · 0 评论 -
线索化二叉树
“test.cpp”#includeusing namespace std;#includeenum Tag{ THREAD, LINK,};templatestruct BinaryTreeThdNode{ T _data; BinaryTreeThdNode* _left; BinaryTreeThdNode* _right; Tag _lefttag;原创 2016-10-01 14:22:46 · 491 阅读 · 0 评论 -
360面试题——搜索二叉树转换成有序的双向链表
360面试题——(不允许创建新的节点)搜索二叉树转换成有序的双向链表这道题有两种思路,一种是创建节点,中序遍历搜索二叉树,然后链表尾插。第二种是线索化二叉树的思想(思路二才是符合题目要求的)核心代码 Node* TreeToList() { if(_root == NULL) { return NULL; } Node* prev = NULL;原创 2016-10-09 16:46:02 · 623 阅读 · 0 评论 -
剑指offer——复杂链表的拷贝
/*struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : label(x), next(NULL), random(NULL) { }};*/class Solution {public:原创 2017-03-23 20:48:14 · 298 阅读 · 0 评论 -
大整数排序
时间限制:1秒 空间限制:32768K 热度指数:463 算法知识视频讲解题目描述对N个长度最长可达到1000的数进行排序。 输入描述:输入第一行为一个整数N,(1<=N<=100)。接下来的N行每行有一个数,数的长度范围为1<=len<=1000。每个数都是一个正数,并且保证不包含前缀零。输出描述:可能有多组测试数据,对于每组数据,将给出的N个数从原创 2017-04-16 17:53:19 · 999 阅读 · 0 评论 -
八进制
#includeusing namespace std;#include#includevoid test(){ int num = 0; vector arr; int key = 0; while(cin>>num){ vector arr; while(num > 0){ key = num % 8; arr.push_back(key); nu原创 2017-04-22 23:32:30 · 325 阅读 · 0 评论 -
面试热题——任意进制(32进制及以下)之间的转换
#define _CRT_SECURE_NO_WARNINGS 1#include using namespace std;#include#include #include//将n进制转换为2进制void nTotwo(vector& v){ //输入的数值是n进制的 int n = 0; cin>>n; //输入的数值是多少 string num; cin>原创 2017-05-25 23:28:52 · 414 阅读 · 0 评论 -
程序员面试金典——输出单层节点
“test.cpp”/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*//*struct ListNode原创 2017-01-02 12:38:38 · 596 阅读 · 0 评论 -
排序——快速排序挖坑法的变形
题目要求代码实现#includeusing namespace std;#includeint Find(vector flag){ for (size_t i = 0;i < flag.size();++i) { if (flag[i] == false) { return i; } } return -1;}vector Swap原创 2016-12-20 23:00:41 · 838 阅读 · 0 评论 -
程序员面试金典——最大连续数列和
class MaxSum {public: int getMaxSum(vector A, int n) { // write code here vector maxnum(n); //子问题最优解的数组 maxnum[0] = A[0]; for(int i = 1;i < n;++i){原创 2016-12-10 21:21:14 · 446 阅读 · 0 评论 -
程序员面试宝典——子串判断
时间限制:3秒 空间限制:32768K 热度指数:545 本题知识点: 字符串 高级结构 题目描述现有一个小写英文字母组成的字符串s和一个包含较短小写英文字符串的数组p,请设计一个高效算法,对于p中的每一个较短字符串,判断其是否为s的子串。给定一个string数组p和它的大小n,同时给定string s,为母串,请返回一个bool数组,每个元素代表p中的对应字符串原创 2016-12-20 22:47:15 · 659 阅读 · 0 评论 -
动态规划——最长升序子序列
问题描述一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, ..., aN),我们可以得到一些上升的子序列(ai1, ai2, ..., aiK),这里1 <= i1 < i2 < ... < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4,原创 2016-11-19 09:58:04 · 3342 阅读 · 0 评论 -
京东——上台阶
上台阶热度指数:2961时间限制:3秒空间限制:32768K本题知识点: 递归 动态规划 算法知识视频讲解题目描述有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或者二级,要走上m级,共有多少走法?注:规定从一级到一级有0种走法。给定一个正整数int n,请返回一个数,代表上楼的方式数。保证n小于等于100。为了防止溢出,请返回结果Mod原创 2016-11-18 13:54:32 · 443 阅读 · 0 评论 -
楚楚街——解密
“test.cpp”#include using namespace std;#include#include #includevoid DFS(const string& str,int len,vector& v,vector& arr){ if (len == str.size()) { for (int i = 0;i < len;i++) { cout原创 2016-11-17 22:51:16 · 667 阅读 · 0 评论 -
蓝桥——你的密码安全吗?
“test.cpp”#includeusing namespace std;#include void test(){ string str; cin>>str; int arr[6] = {0}; for(int i = 0;i < 6;i++) { int j = i; int sum = 0; while(j < str.length()) {原创 2016-11-12 11:13:59 · 428 阅读 · 0 评论 -
面试题——大数据处理解题思路
(1)给一个超过100G大小的log file,log中存着IP地址,设计算法找到出现次数最多的IP地址?解题思路:IP地址是一个32位的字符串,100G在内存中肯定放不下,所以我们必须通过不同的手段去解决。我们可以将100G的文件切分成1000个小文件,对每个文件编号,每个文件的大小是512M,这样内存是很容易读取的。我们将IP地址通过字符串哈希函数处理成对应的整树,将整数模上文件个原创 2016-11-10 22:24:18 · 698 阅读 · 0 评论 -
腾讯面试题——位图的应用
题目:给40亿个不重复的无符号整型,没排过序。给一个无符号整数,如何快速判断这个数是否存在在这40亿个数中set()函数图解reset()函数图解“BitMap.h”#pragma once#includeclass BitMap{public: //range 范围 BitMap(size_t range) { //size_t有四个字原创 2016-11-07 15:17:14 · 682 阅读 · 0 评论 -
去哪儿2015研发工程师——首个重复字符
“test.cpp”class FirstRepeat {public: char findFirstRepeat(string A, int n) { // write code here if(n > 500) return 0; int ch[256] = {0}; for原创 2016-11-03 22:13:38 · 424 阅读 · 0 评论 -
腾讯2016研发工程师编程题——微信红包
“test.cpp”class Gift {public: int getValue(vector gifts, int n) { // write code here if(gifts.size() == 0 || gifts.size() != n) return 0; //先给红包数组排序原创 2016-11-02 19:06:43 · 1191 阅读 · 1 评论 -
腾讯2016研发工程师编程题——生成格雷码
“test.cpp”class GrayCode {public: vector getGray(int n) { // write code here vector gray; if(n == 1){ gray.push_back("0"); gray.push_bac原创 2016-10-31 22:42:07 · 509 阅读 · 0 评论 -
程序员面试金典——密码验证合格程序
“test.cpp”#includeusing namespace std;#includeint main(){ string str; while(cin>>str){ int count[4] = {0}; if(str.size() <= 8) goto NG; for(size_t i = 0;i < str.size(原创 2016-10-30 23:00:02 · 444 阅读 · 0 评论 -
华为机试——魔术索引
"test.cpp"没想到,既然暴力法会通过所有的测试用例原创 2016-10-30 21:50:05 · 515 阅读 · 0 评论 -
今日头条——回文编码
"test.cpp" #includeusing namespace std;#includestring Reversal(string str,int p,int l){ int left = p; int right = p + l -1; while(left < right) { swap(str[left],str[right]);原创 2016-10-28 14:54:47 · 736 阅读 · 0 评论 -
华为机试——字符串最后一个字符的长度
"test.cpp"#includeusing namespace std;#includevoid test(){ string str; getline(cin,str); if(str.length() >= 5000 || str.length() == 0) { return; } string::iterator it = st原创 2016-10-28 13:55:21 · 448 阅读 · 0 评论 -
面试题——判断一棵树是否是平衡二叉树
bool IsBlance() { return _IsBlance(_root); }protected: bool _IsBlance(Node* root) { if (root == NULL) return true; int leftHeight = _Height(root->_left); int rightHeight = _Height(r原创 2016-10-25 16:26:04 · 1782 阅读 · 0 评论 -
网易秋招编程题——计算糖果
“test.cpp”#includeusing namespace std;void test(){ int x,y,j,k; cin>>x; cin>>y; cin>>j; cin>>k; int a = 0; if((x + j) % 2 == 0) { a = (x + j) / 2;原创 2016-10-16 11:36:13 · 891 阅读 · 0 评论 -
网易秋招编程题——回文序列
“test.cpp”#includeusing namespace std;int comb(int* nums,int start,int end){ int count = 0; int left = nums[start]; int right = nums[end]; while(start < end && left != right) { if(left <原创 2016-10-17 23:17:21 · 1036 阅读 · 0 评论 -
网易秋招编程题——优雅的点
“test.cpp”#includeusing namespace std;#includevoid test(){ int num = 0; int count = 0; cin>>num; for(int i = 0;i < sqrt(num);i++) { double j = sqrt(num - i*i); if(int(j) == j)原创 2016-10-17 23:19:52 · 726 阅读 · 0 评论 -
网易秋招编程题——翻转数字
“test.cpp”#includeusing namespace std;int rev(int x){ int tmp = 0; while(x > 0) { tmp = tmp * 10 + x % 10; x = x / 10; } return tmp;}void test(){ int x = 0; int y = 0; cin>>x>>y;原创 2016-10-18 14:31:42 · 395 阅读 · 0 评论 -
网易秋招编程题——最大的奇约数
代码不成熟“test.cpp”#includeusing namespace std;int f(int num){ int max = 1; if(num % 2 != 0) { return num; } for(int i = 2;i < num;i++) { int j = num / i; if(j % 2 != 0) { i原创 2016-10-19 22:07:23 · 685 阅读 · 0 评论