链家笔试题整理
2017-08-27 09:59
316 查看
1.撤销操作如何实现?
撤销功能的实现备忘录模式2.1000万个数找出两数之和为K的数
用HashMap实现,key为 具体的数字,value为数字出现的次数3.一个含有n个元素的数组,找出m个数使其和为K
public class Test { public static void main(String[] args) { int[] nums ={ 1, 2, 3, 4, 5, 6 }; int sum=10; Test test = new Test(); test.findNums(nums,sum); } public void findNums(int[] nums,int sum){ int length = nums.length; int count = 1<< length; for(int i=1;i<count;i++){ int temp =i; int index = length-1; int temp_sum=0; while (temp>0) { if ((temp & 1) == 1) { temp_sum += nums[index]; } temp=temp>>1; index--; } if(temp_sum==sum){ printNums(nums,i); System.out.println(); } } } public void printNums(int[] nums,int i){ int index = nums.length-1; while (i>0){ if((i&1)==1){ System.out.print(nums[index]+" "); } i=i>>1; index--; } } }
4.二叉树中两个节点的最近公共祖先
public int query(BinaryTreeNode node1, BinaryTreeNode node2, BinaryTreeNode root) { int left = node1.value; int right = node2.value; BinaryTreeNode parent = null; if (left > right) { int temp = left; left = right; right = temp; } while (true) { if (root.value < left) { parent = root; root = root.right; } else if (root.value > right) { parent = root; root = root.left; } else if (root.value == left || root.value == right) { return parent.value; } else { return root.value; } } }
5.IP 与城市的映射
HashMap实现相关文章推荐
- Java工程师面试题,整理自网络与博主各种笔试面试,持续更新
- C++学习笔记(二十四)笔试编程题整理
- 【自己整理的答案】2013百度校园招聘-机器学习和数据挖掘工程师-笔试题
- java面试笔试题整理
- 2011 IT公司笔试面试题目整理
- IBM笔试题整理,包括题型和真题
- Android笔试面试题整理
- 笔试整理二
- 【Killua笔试面试题整理】最大间隔问题
- 笔试面试题 整理---2
- C++笔试面试题 从网上整理的,带答案
- java笔试题整理--有答案
- java面试笔试题整理
- 在线笔试问题整理1
- 链家笔试:素数打表
- 【Killua笔试面试题整理】有序矩阵查找值
- 【链家笔试题】部队分组
- 2018链家校招内推-大数据开发工程师笔试编程题
- thoughtworks笔试整理