面试总结-百度(1)

百度数据挖掘部门

       自我介绍,扯了一些项目方面的东西,就是简历上的,然后开始写代码,最后问你有没有什么问题。

题目如下:

(1)用两个栈实现一个队列(优化后解)

public class QueueImplementByTwoStacks {
            
	  Stack<Integer> a=new Stack<Integer>(); 
	  Stack<Integer> b=new Stack<Integer>();
	  public void add(int num){
		  a.push(num);
	  }
	  public int pop(){
		  if(!b.empty()){
			  return b.pop();
		  }
		  else{
			  while(!a.empty()){
				  b.push(a.pop());
			  }
			  return b.pop();
		  }
	  }
	  
	  public static void main(String[] args){
		  QueueImplementByTwoStacks queue=new QueueImplementByTwoStacks();
		  
		  queue.add(8);
		  queue.add(9);
		  System.out.print(""+queue.pop());
	  }
}

(2)矩阵乘法


public class MultiplyMatrix {
        
	  public int[][] multiply(int[][] a,int[][] b){
        	int[][] result=new int[a.length][b[0].length];
        	for(int i=0;i<a.length;i++){
        		for(int j=0;j<b[0].length;j++){
        			for(int k=0;k<a[0].length;k++){
        				result[i][j]+=a[i][k]*b[k][j];
        			}
        		}
        	}
        	return result;
        } 
}





/********************************

* 本文来自博客  “李博Garvin“

* 转载请标明出处:http://blog.csdn.net/buptgshengod

******************************************/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值