创新工场笔试题
2014-09-24 21:23
232 查看
1.树的子结构问题,参照《剑指offer》上面试题18.
2.翻转字符串;
3.加油站问题,参见leetcode题目Gas Station
bool DoseTree1HaveTree2(BinaryTreeNode *pRoot1, BinaryTreeNode *pRoot2) { if(pRoot2 == NULL) return true; if(pRoot1 == NULL) return false; if(pRoot1->m_nValue != pRoot2->m_nValue) return false; return DoseTree1HaveTree2(pRoot1->m_pLeft, pRoot2->m_pLeft) && DoseTree1HaveTree2(pRoot1->m_pRight, pRoot2->m_pRight); } bool HasSubTree(BinaryTreeNode *pRoot1, BinaryTreeNode *pRoot2) { bool result = false; if(pRoot1 != NULL && pRoot1 != NULL) { result = DoesTree1HaveTree2(pRoot1, pRoot2); if(!result) result = HasSubTree(pRoot1->m_pLeft, pRoot2); if(!result) result = HasSubTree(pRoot1->m_pRight, pRoot2); } return result; }
2.翻转字符串;
void reverse(string s) { int n = s.size(); int i = 0, j = n-1; while(i <= j) { swap(s[i], s[j]); i++; j--; } }
3.加油站问题,参见leetcode题目Gas Station
int canCompleteCircuit(vector<int> &gas, vector<int> &cost) { int n=gas.size(); if(n==0) return -1; int sum=0; int dif=0; int result=0; for(int i=0;i<n;i++) { sum+=gas[i]-cost[i]; dif+=gas[i]-cost[i]; if(sum<0) { result=(i+1)%n; sum=0; } } if(dif<0) return -1; return result; }
相关文章推荐
- 创新工场2013.9.16笔试、9.17一面、9.18双选会
- 2014创新工场校招笔试题及参考答案
- 2012.09.20创新工场笔试
- 创新工场笔试题2013年校园招聘
- 创新工场笔试小记(创新工厂算法笔试题)
- 创新工场笔试题2014年,求概率
- 2014创新工场笔试题
- [2014创新工场笔试]求一个正数的开方,不能使用库函数sqrt,精度在0.001以内即可
- 创新工场2011年校园招聘笔试题
- 创新工场一道笔试题
- 2013 创新工场笔试题
- 创新工场笔试、小米科技笔试、百度笔试 研发部门
- [历年IT笔试题]2014年创新工场校园招聘笔试题及答案
- 2014 创新工场校园招聘笔试题(武汉站)
- 创新工场笔试题
- 创新工场2012笔试编程---捕鱼和分鱼
- 【面试笔试-c/c++】2013年校园招聘创新工场笔试题(北邮场)
- 2012-9-25 创新工场笔试题
- 创新工场笔试题2014 校园招聘 ---武汉站
- 求一个正整数N的开方,要求不能用库函数sqrt(),结果的精度在0.001(创新工场笔试题)