广联达2016西安研发笔试题
来源:互联网 发布:阿里云服务器学生认证 编辑:程序博客网 时间:2024/05/21 19:46
- 华为机试考过的字符串压缩问题,没有难度。
- 给出了平衡二叉树的概念,让写一个函数判断是否为平衡二叉树。剑指offer书本的原题
方法一:
struct BinaryTreeNode{ int m_Value; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight;};int TreeDepth(BinaryTreeNode* pRoot){ if (pRoot == NULL) return 0; int nLeftDepth = TreeDepth(pRoot->m_pLeft); int nRightDepth = TreeDepth(pRoot->m_pRight); return (nLeftDepth>nRightDepth)?(nLeftDepth+1):(nRightDepth+1);}bool IsBalanced(BinaryTreeNode* pRoot){ if(pRoot== NULL) return true; int nLeftDepth = TreeDepth(pRoot->m_pLeft); int nRightDepth = TreeDepth(pRoot->m_pRight); int diff = nRightDepth-nLeftDepth; if (diff>1 || diff<-1) return false; return IsBalanced(pRoot->m_pLeft)&&IsBalanced(pRoot->m_pRight);}
方法二:
bool IsBalanced(BinaryTreeNode* pRoot, int* depth){ if(pRoot== NULL) { *depth = 0; return true; } int nLeftDepth,nRightDepth; bool bLeft= IsBalanced(pRoot->m_pLeft, &nLeftDepth); bool bRight = IsBalanced(pRoot->m_pRight, &nRightDepth); if (bLeft && bRight) { int diff = nRightDepth-nLeftDepth; if (diff<=1 || diff>=-1) { *depth = 1+(nLeftDepth > nRightDepth ? nLeftDepth : nRightDepth); return true; } } return false;}bool IsBalanced(BinaryTreeNode* pRoot){ int depth = 0; return IsBalanced(pRoot, &depth);}
- 找到两个单链表的交点,如果不想交返回空,还有判断链表是否有环都是链表最基本的操作,剑指offer都有非常类似的题。
参考:http://blog.chinaunix.net/uid-20754793-id-177773.html - 跟广联达业务比较紧密的一道题,其实就是建立业务描述和真实数据映射关系,题目比较长思路简单。
- 输入一个矩阵,顺时针打印矩阵的数据。也是剑指offer原题
package junit;public class PrintMatrix { public static void printCircle(int[][] matrix, int startX, int startY, int endX, int endY) { // only one column left if (startY == endY) { for (int i = startX; i <= endX; i++ ) { System.out.println(matrix[i][endY]); } return; } // only one row left if (startX == endX) { for (int i = startY; i <= endY; i++ ) { System.out.println(matrix[startX][i]); } return; } // 注意交界点不要打印两次 for (int i = startY; i < endY; i++ ) { System.out.println(matrix[startX][i]); } for (int i = startX; i < endX; i++ ) { System.out.println(matrix[i][endY]); } for (int i = endY; i > startY; i-- ) { System.out.println(matrix[endX][i]); } for (int i = endX; i > startX; i-- ) { System.out.println(matrix[i][startY]); } } public static void printMatrix(int[][] matrix) { if (matrix == null) { return; } int startX = 0; int startY = 0; int endY = matrix[0].length - 1; int endX = matrix.length - 1; while ((startX <= endX) && (startY <= endY)) { printCircle(matrix, startX, startY, endX, endY); startX++; startY++; endX--; endY--; } } public static void main(String[] args) { int[][] matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; printMatrix(matrix); }}
- 两个版本号比较,就是字符串的一些处理,java 使用split 函数切分比较就轻松完成。这里版本号比较只有数字和. 所以难度比字母存在更低。
package junit;public class CompareVersion { public static int compare_string(String str1, String str2) { // 特殊字符一定要注意转义,是个坑 String[] strs1 = str1.split("\\."); String[] strs2 = str2.split("\\."); int i, j; int num1 ,num2; for (i = 0, j = 0; i < strs1.length && j < strs2.length; i++, j++) { num1 = Integer.parseInt(strs1[i]); num2 = Integer.parseInt(strs2[j]); if(num1 > num2) return 1; if(num1 < num2) return -1; } if (i == strs1.length && j == strs2.length) { return 0; } if (i == strs1.length) { return -1; } else { return 1; } } public static void main(String[] args) { String version1 = "1.0.1"; String version2 = "1.0"; System.out.println(compare_string(version1, version2)); }}
其他一些题目也基本都是来自剑指offer。
0 0
- 广联达2016西安研发笔试题
- 2014百度校招PC客户端研发笔试题(西安站)
- 百度2015校园招聘笔试题——研发工程师(西安站)
- 腾讯2015校园招聘研发工程师笔试题(西安站)
- 百度2015校园招聘笔试题——研发工程师(西安站)
- 2015百度校园招聘软件研发类笔试题(笔试时间:2014-9-14,西安、哈尔滨、大连站)
- 2015百度校园招聘软件研发类笔试题(笔试时间:2014-9-14,西安、哈尔滨、大连站)
- 2015百度校园招聘软件研发类笔试题(笔试时间:2014-9-14,西安、哈尔滨、大连站)
- 2012年阿里巴巴笔试 西安站 研发/算法工程师
- 腾讯2016实习招聘(西安)部分在线笔试题
- 阿里巴巴2016研发工程师笔试题
- 2016腾旭研发工程师笔试题
- 2016VMware研发笔试题回忆总结
- 迅雷2016研发工程师笔试题
- 猎豹移动2016研发工程师笔试题
- 携程2016研发工程师笔试题
- 网易2016研发工程师笔试题
- 腾讯2016研发工程师笔试题(三)
- OpenGL投影矩阵与相机模型(Set Projection Matrix for Pinhole Camera Model)
- Pascal's Triangle II
- 第四十四天 指南针、百度地图
- 20150922——第一个项目总结
- CRM-BaseDao的抽取
- 广联达2016西安研发笔试题
- ViewPagerIndicator-master源码分析 3
- BestCoder#56 Clarke and puzzle
- hdu acm 2569
- react的入门讲解
- listview加载更多
- LeetCode(40) Median of Two Sorted Arrays (两排序数组中位数)
- HDOJ 题目1158Employment Planning(DP)
- Android APP性能优化和内存优化