LinkedIn

1. reflection of tree,写方程,判断A是不是B的镜面图。
A : a    B :   a
    /              \
   b                b
     \             /
      c           c

    public boolean isSysmetric(TreeNode r1, TreeNode r2) {
    	if(r1 == null && r2 == null) return true;
    	if(r1 == null || r2 == null) return false;
    	if(r1.val != r2.val) return false;
    	
    	Queue<TreeNode> q1 = new LinkedList<TreeNode>();
    	Queue<TreeNode> q2 = new LinkedList<TreeNode>();
    	q1.offer(r1); 
    	q2.offer(r2);
    	
    	while(!q1.isEmpty() && !q2.isEmpty()) {
    		TreeNode cur1 = q1.poll();
    		TreeNode cur2 = q2.poll();
    		if(cur1.val != cur2.val) return false;
    		
    		if(cur1.left == null && cur2.right != null) return false;
    		else if(cur1.left != null && cur2.right == null) return false;
    		else if(cur1.left != null && cur2.right != null) {
    			q1.offer(cur1.left);
    			q2.offer(cur2.right);
    		}
 
    		if(cur1.right == null && cur2.left != null) return false;
    		else if(cur1.right != null && cur2.left == null) return false;
    		else if(cur1.right != null && cur2.left != null) {
    			q1.offer(cur1.right);
    			q2.offer(cur2.left);
    		}
    	}
    	if( !q1.isEmpty() || !q2.isEmpty()) return false;
    	
    	return true;
    }


2.sum of nestedinteger, nestedinteger就是可能是integer,也可能是一个list 包含更多的nestedinteger,比如 {1,2,{3,4}}然后每一层weight都加1,所以这个例子的话sum就是 1*1+2*1+3*2+4*2

refer: http://stackoverflow.com/questions/19088008/sum-of-elements-in-a-nested-weighted-by-their-depth

    private int getSum(List<NestedInteger> input, int level) {
    	int sum = 0;
    	for(int i = 0 ; i < input.size(); i++) {
    		if(input.get(i).isInteger()) 
    			sum += level * input.get(i).getInteger();
    		else 
    			sum += getSum(input.get(i).getList(), level + 1);
    	}
    	return sum;
    }
    
    public int depthSum (List<NestedInteger> input)
    {
         //Implement this function
    	return getSum(input, 1);
    }

    /**
     * This is the interface that allows for creating nested lists. You should not implement it, or speculate about its implementation
     */
    public interface NestedInteger 
    {
        // Returns true if this NestedInteger holds a single integer, rather than a nested list
        public boolean isInteger();

        // Returns the single integer that this NestedInteger holds, if it holds a single integer
        // Returns null if this NestedInteger holds a nested list
        public Integer getInteger();

        // Returns the nested list that this NestedInteger holds, if it holds a nested list
        // Returns null if this NestedInteger holds a single integer
        public List<NestedInteger> getList();
    }  



3.maximum subarray


4.pow 求a的b次方


5. construct a string using another string, 给你string A和string B,问你能不能用B里面的字母拼出A


6.permutation



7.设计题,设计一个在线购物平台。是我见过最耐心的阿三哥。人非常好,也没口音,所有面试里面最舒畅的一轮的。让我设计amazon的产品页。主要是high level的结构,以及一些具体跟性能有关的细节。因为我确实还没上过concurrency的课。。所以坦白的跟他说了,我们就先绕开并行的问题,谈了谈别的。然后他大概有给我上了几分钟的并行的课。。。不过他提出的问题我都答出来了。。所以这一轮感觉变数很大。。


8.第一轮是coding,一个白人,一上来让我reverse strings。。我心想也太简单了吧。然后他说要in place...我想了一下。。。卧槽。。java里面肯定不可能啊= =。。。后来才明白,可以用char[]来做输入。然后就简单了。所以这第一题,不知道是算他自己没说清楚,还是我没问清楚。。我确实说了java里string做不到。后来问的encode和decode trees。一开始我用的level traversal,然后写到一半他说其实用preorder也可以。我就又改写,然后就没写完decoding的部分。。所以这一轮发挥也不是特别好。


9.coding,一个白人和一个同胞,pow和edit distance...pow要求输入和输出都是float,所以我就引入了一个accuracy


10.说一下Supervised Learning和Unsupervised Learning的区别。Supervised Learning的一些主要方法??


11.public boolean isInList(float target, float[] list) 排序以后又旋转过,找值


12.public void printFactors(int n)
  example:
  input:12 
  output:
    1 * 12

    2 * 6

    2 * 2 * 3

    3 * 4


  input:32

  output:

    1 * 32

    2 * 16

    2 * 2 * 8

    2 * 2 * 2 * 4

    2 * 2 * 2 * 2 * 2

    2 * 4 * 4

    4 * 8

13.第一个是 是否是个数字,我已经被问了2次这个题,很囧,各种问条件,支持E吗,云
云。然后就说了下思路什么的,开始写。(Valid Number)




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值