腾讯 一面 二面 2017暑期实习招聘

版权声明:给别人一份尊重,留自己一方安心。 https://blog.csdn.net/Zheng548/article/details/70173634

腾讯一面

  • 没有自我介绍,先拿下我的简历,让我在白纸上画,项目的架构。我画了几分钟,然后跟面试官介绍。
  • 这次最大的一个败点是,我没有在手机上安装项目应用,这也是线下面试,与线上面试的一个不同点。
  • 后来写一个题,合并数组的题。
  • 总结,腾讯这次我感觉看项目,清楚项目的整体架构,后很好,最好安装上去,我估计这次是跪了。不过也没关系,我的项目经历确实有点少,这次面试跟我之前的面试不太一样,这次真的比较看实力,java和jvm,计算机网络,其他的都没有问。

一面做题

/**
 * 腾讯Android岗,一面面试题目
 * Created by Zheng548 on 2017/4/13 .
 * 转载请注明出处(注明作者,和原链接)
 * @author Zheng548
 * 链接:http://blog.csdn.net/zheng548/article/details/70173634
 * 
 * 有两个排序的数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2。请实现一个函数,把A2中的所有数字插入到A1中并且所有的数字是排序的。
 * 以下是我的实现
 */
public class MergeSortedArray {
    public static void insertSortedArray(int[] a1, int[] a2) {
        if (a1 == null || a1.length <= 0 || a2 == null || a2.length <= 0) {
            return;
        }
        //因为a1末尾有足够多的内存空间,所以a1中的元素个数小于a1.length();
        //所以,先求a1中元素的个数
        int cntInA1 = 0;
        while (a1[cntInA1] != 0) {
            cntInA1 ++;
        }
        int cntInA2 = a2.length; //a2数组空间全部用完,没有多余的内存

        int mergeSize = cntInA1 + cntInA2;
        mergeSize --;
        cntInA1 --;
        cntInA2 --;

        while (cntInA2 >= 0) {
            if (a2[cntInA2] >= a1[cntInA1]) {
                a1[mergeSize --] = a2[cntInA2 --];
            } else {
                a1[mergeSize --] = a1[cntInA1 --];
            }
        }
    }

    public static void main(String[] args) {
        int[] a1 = new int[10];
        a1[0] = 1; a1[1] = 2; a1[2] = 4; a1[3] = 5; a1[4] = 8;
        int[] a2 = new int[] {3,6,7};
        insertSortedArray(a1, a2);
        for (int val : a1) {
            System.out.print(val + " ");
        }
    }
}

二面

面试官非常和蔼,非常友善。他先我进行了自我介绍,然后聊了下项目。聊的时间也不是太长,后来,问我对应聘的岗位有没有了解,自己为什么能胜任这个岗位?
期间,做了一道题,感觉腾讯非常重视做题。
那个题是这样的:

/**
 * 腾讯Android岗,二面面试题 《去除驼峰字符串》
 * 面试官写的原题记不得了,大概意思是这样的:
 * 给定一个驼峰样式的字符串 例如“...adbabfgh.....”,其中bab为驼峰,
 两个一样的字符夹着一个不一样的字符, 返回去掉所有驼峰的字符串。
 * Created by Zheng548 on 2017/4/14 0014.
 * 转载请注明出处(注明作者,和原链接)
 * @author Zheng548
 * 链接:http://blog.csdn.net/zheng548/article/details/70173634
 */
public class T {

    public static void main(String[] args) {
        System.out.println(fun(" "));
        System.out.println(fun("abele"));
        System.out.println(fun("abelea"));
        System.out.println(fun("abeleaea"));
        System.out.println(fun("abeleaeaa"));
        System.out.println(fun("abeleaeaaw"));
        System.out.println(fun("abeleaeaawq"));
        System.out.println(fun("abeleaeaawqk"));
        System.out.println(fun("abeleaeaawqkl"));

    }

    private static String fun(String str) {
        /**
         * 健壮性分析str == null 或者str.length <= 0
         */
        if (str == null || str.length() <= 0) {
            return null;
        }
        /**
         * 当字符串长度小于等于2,不可能存在驼峰,直接返回
         */
        if (str.length() <= 2) {
            return str;
        }

        StringBuilder sb = new StringBuilder();

        int i; //全局变量i,用于遍历字符串
        boolean flag = false; //标志位,用于递归出口条件判断。初始为false
        for (i = 0; i < str.length() - 2; i ++) {
            if (str.charAt(i) == str.charAt(i + 2)
                    && str.charAt(i) != str.charAt(i + 1)) {
                //驼峰存在i = i + 2,同时外层for 循环 + 1,共计增加3
                i = i + 2;
                flag = true; //当有驼峰时,说明递归没有结束,仍需判断
                continue;
            }
            /**
             * 若str.charAt(i)不是驼峰的组成部分,则append到后面
             */
            sb.append(str.charAt(i));
        }
        /**
         * flag 为flase,说明if (str.charAt(i) == str.charAt(i + 2)
         && str.charAt(i) != str.charAt(i + 1))
         没有只i系那个,也就是没有驼峰,递归出口,返回
         */
        if (!flag) {
            return str;
        }

        /**
         * 上面for循环有i < str.length() - 2;的限制,所以下行代码,处理字符串末尾字符
         */
        sb.append(str.substring(i));

        /**
         * 尾递归调用
         */
        return fun(sb.toString());
    }
}

猜你喜欢

转载自blog.csdn.net/Zheng548/article/details/70173634