面试总结(二)---北京数梦工厂

【笔试部分】
一、 给定一个  ×  n  的二维矩阵,将矩阵顺时针旋转 90 度。
示例 1:
给定 matrix = [ [1,2,3], [4,5,6], [7,8,9]],原地旋转输入矩阵,使其变为:[ [7,4,1], [8,5,2], [9,6,3]]
public class Rotate {
	public static void main(String[] args) {
		int[][] test= {{1,2,3},{4,5,6},{7,8,9}};
		print(test);
		Rotate90(test);
		print(test);
	}
    public static void Rotate90(int[][] matrix){
    	//转置
		for(int i=0;i<matrix.length;i++) {
			for(int j=i;j<matrix[i].length;j++) {
				int tmp=matrix[i][j];
				matrix[i][j]=matrix[j][i];
				matrix[j][i]=tmp;
			}
		}
		//列对称
		for(int i=0;i<matrix.length;i++) {
			for(int j=0;j<matrix[i].length/2;j++) {
				int tmp=matrix[i][j];
				matrix[i][j]=matrix[i][matrix[i].length-1-j];
				matrix[i][matrix[i].length-1-j]=tmp;
			}
		}
	}
    public static void print(int[][] matrix){
    	for(int i=0;i<matrix.length;i++) {
    		for(int j=0;j<matrix[i].length;j++) {
    			System.out.print(matrix[i][j]+",");
    		}
    		System.out.println();
    	}
    }
}
二、先序遍历二叉树

先创建二叉树,可以使用递归也可以不使用递归。

import java.util.LinkedList;

public class BinaryTree<T> {
	class TreeNode<T>
	{
		public T data;
		public TreeNode<T> left;
		public TreeNode<T> right;
		
		public TreeNode(T data,TreeNode<T> left,TreeNode<T> right) {
			this.data=data;
			this.left=left;
			this.right=right;
		}
	}
	/**
	 * 先序创建二叉树(递归)
	 * @param treeData
	 * @return
	 */
	public TreeNode<T> creatBinaryTree(LinkedList<T> treeData){
		TreeNode<T> root=null;
		T data=treeData.removeFirst();
		if(data!=null) {
			root=new TreeNode<T>(data, null, null);
			root.left=creatBinaryTree(treeData);
			root.right=creatBinaryTree(treeData);
		}
		return root;
		
	}
	/**
	 * 先序遍历(递归)
	 * @param root
	 */
	public void PrintBinaryTreePreRecur(TreeNode<T> root){
		if(root!=null) {
			System.out.print(root.data);
			PrintBinaryTreePreRecur(root.left);
			PrintBinaryTreePreRecur(root.right);
		}
	}
	/**
	 * 中序遍历(递归)
	 * @param root
	 */
	public void PrintBinaryTreeMidRecur(TreeNode<T> root) {
		if(root!=null) {
			PrintBinaryTreeMidRecur(root.left);
			System.out.print(root.data);
			PrintBinaryTreeMidRecur(root.right);
		}
	}
	/**
	 * 后序遍历(递归)
	 * @param root
	 */
	public void PrintBinaryTreeBacRecur(TreeNode<T> root) {
		if(root!=null) {
			PrintBinaryTreeBacRecur(root.left);
			PrintBinaryTreeBacRecur(root.right);
			System.out.print(root.data);
		}
	}
	/**
	 * 先序遍历(非递归)
	 * @param root
	 */
	public void PrintBinaryTreePreUnrecur(TreeNode<T> root) {
		TreeNode<T> p=root;
		LinkedList<TreeNode> stack = new LinkedList<>();
		
		while(p!=null||!stack.isEmpty()) {
			if(p!=null) {
				stack.push(p);
				System.out.print(p.data);
				p=p.left;
			}else {
				p=stack.pop();
				p=p.right;
			}
		}
	}
	public void PrintBinaryTreeMidUnrecur(TreeNode<T> root) {
		TreeNode<T> p=root;
		LinkedList<TreeNode> stack = new LinkedList<>();
		while(p!=null||!stack.isEmpty()) {
			if(p!=null) {
				stack.push(p);
				p=p.left;
			}else {
				p=stack.pop();
				System.out.print(p.data);
				p=p.right;
				stack.peek();
			}
		}
	}
	/**
	 * 后序遍历(非递归)
	 * @param root
	 */
	public void PrintBinaryTreeBacUnrecur(TreeNode<T> root) {
		  class NodeFlag<T>
	        {
	            TreeNode<T> node;
	            char tag;
	            public NodeFlag(TreeNode<T> node, char tag) {
	                super();
	                this.node = node;
	                this.tag = tag;
	            }
	        }
	        LinkedList<NodeFlag<T>> stack=new LinkedList<>();
	        TreeNode<T> p=root;
	        NodeFlag<T> bt;
	        //栈不空或者p不空时循环  
	        while(p!=null || !stack.isEmpty())
	        {
	            //遍历左子树
	            while(p!=null)
	            {
	                bt=new NodeFlag(p, 'L');
	                stack.push(bt);
	                p=p.left;
	            }
	            //左右子树访问完毕访问根节点 
	            while(!stack.isEmpty() && stack.getFirst().tag=='R')
	            {
	                bt=stack.pop();
	                System.out.print(bt.node.data);
	            }
	            //遍历右子树
	            if (!stack.isEmpty()) 
	            {
	                bt=stack.peek();
	                bt.tag='R';
	                p=bt.node;
	                p=p.right;
	            }
	        }
		}	
	/**
	 * 层次遍历(非递归)----队列实现
	 * @param root
	 */
	public void PrintBinaryTreeLayerUnrecur(TreeNode<T> root) {
		LinkedList<TreeNode> queue = new LinkedList<>();
		TreeNode<T> p;
		queue.push(root);
		while(!queue.isEmpty()) {
			p=queue.removeFirst();
			System.out.print(p.data);
			if(p.left!=null) 
				queue.addLast(p.left);
			if(p.right!=null)
				queue.addLast(p.right);
		}
		
		
	}	

}

编写一个测试二叉树遍历的例子:

import java.util.LinkedList;

public class TestBinaryTree<T> {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
/*
 * 二叉树结构如下
 *            A
 *       B         C
 *    D     E   F     G
 *  H   I        J 
 */

		BinaryTree<Character> binaryTree = new BinaryTree<>();
		LinkedList<Character> tree = new LinkedList<>();
		tree.add('A');
		tree.add('B');
		tree.add('D');
		tree.add('H');
		tree.add(null);
		tree.add(null);
		tree.add('I');
		tree.add(null);
		tree.add(null);
		tree.add('E');
		tree.add(null);
		tree.add(null);
		tree.add('C');
		tree.add('F');
		tree.add(null);
		tree.add('J');
		tree.add(null);
		tree.add(null);
		tree.add('G');
		tree.add(null);
		tree.add(null);
		BinaryTree<Character>.TreeNode<Character> root = binaryTree.creatBinaryTree(tree);
		//先序遍历(递归)
        binaryTree.PrintBinaryTreePreRecur(root);
        System.out.println();
        //中序遍历(递归)
        binaryTree.PrintBinaryTreeMidRecur(root);
        System.out.println();
        //后序遍历(递归)
        binaryTree.PrintBinaryTreeBacRecur(root);
        System.out.println();


        //先序遍历(非递归)
        binaryTree.PrintBinaryTreePreUnrecur(root);
        System.out.println();
        //中序遍历(非递归)
        binaryTree.PrintBinaryTreeMidUnrecur(root);
        System.out.println();
        //后序遍历(非递归)
        binaryTree.PrintBinaryTreeBacUnrecur(root);
        System.out.println();
        //层次遍历(非递归)
        binaryTree.PrintBinaryTreeLayerUnrecur(root);
        System.out.println();

	}
}

【面试部分】
一面:(技术面)

1、静态函数初始化与它的构造函数调用

2、Linux字符串查找指令

3、服务器搭建部署过程及遇到的问题

    就是按照JDK、Tomcat等那一系列流程,能证明你之前确实做过就可以。比如我当时就说了mysql与mariaDB的问题。

可参考我的另一篇博文:在阿里云上配置JAVAWEB项目

4、面试官比较随和,到这个时候基本已经成了我的主场,全程被我牵着走。

二面:(管理面)

1、自我介绍:不要太尬,最好准备个大概草稿,一般面试到了这个环节,就说明你技术没啥问题啦,主要看看今后和你共事会不会有难度,正常聊天就好。

2、说说你有什么兴趣爱好:实话实说,打游戏也可以。当然你也可以敲代码,虽然听起来有点装13。

3、根据你简历上的实习、校园经历问问一些活动:这个环节就需要表现出你对生活的热情,良好的组织管理能力。千万不要自我贬低,这个活动比较LOW啦,那个活动是学校强制参与之类的,如果不好你干嘛要写上啊!总之就是我很牛,活动(实习)很成功,同学(事)关系非常好。放心大胆的吹吧,记得打个草稿就好。2008年感动中国获奖人物就是你。

4、有没有收到其他offer:这个问题因人而异,我的建议是一定要说“有”,没有也要说有,这是你实力的表现,既然能走到这个环节,说明你的技术不错,得到了很多家公司的认可。也有人说,公司会因为你有其他家的offer而拒绝你,这个完全不用担心,如果出现这种情况,说明公司对自己不自信,那么你可以考虑换家公司啦。

附上公司offer以供参考:



*****over-chen*****



猜你喜欢

转载自blog.csdn.net/m0_37570217/article/details/80554971
今日推荐