腾讯云智笔试题(Java后端)

20道选择题,5道填空题,两道编程题。

1. 20道选择题

选择题考的比较系统,包括Java设计模式,c语言,linux,计算机网络等,操作系统等。

2. 5道填空题

  1. 有两道 递归代码考察;
  2. ABCEDFG七人站队,要求A必须在B的左边(可不相邻),求排法。牛客有题;
  3. 假设网络 带宽128Mb/s,网络单向延时100ms,1000哥个客户端同时向服务器传输64kb大小的文件,每个请求大小为64kb,服务器磁盘并发写入的速度30MB/s,在传输过程中,服务器吞吐量为?MB/s单个请求响应时间?ms

3. 2道编程题

  1. Leetcode 第15题. 三数之和
import jdk.nashorn.internal.ir.annotations.Ignore;

import javax.management.relation.RoleInfo;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    
    
    /*
    * 三数之和的解题思路:
    *       - 暴力法: 三次for循环,时间复杂度太高
    *       - 内部采用双指针法,将两次for循环降为一次,
    *       - 总体就是采用双指针法,将三次for循环变为两次for循环。
    *       - 难点: 去重,结果集不能出现重复。外部 i 去重,内部 left 和 right 指针去重。
    * */
    public List<List<Integer>> threeSum(int[] nums) {
    
    
        // 首先进行排序
        Arrays.sort(nums);
        int left;
        int right = nums.length - 1;
        // 存储结果列表
        List<List<Integer>> resultList = new ArrayList<>();
        
        for (int i = 0; i < nums.length -  1; i++){
    
    
            // 剪枝操作
            // 因为对数组进行了排序,所以数组之和如果要等于0.第一个元素肯定不能大于0,
            if (nums[i] > 0) {
    
    
                return resultList;
            }
            // 赋值左右指针
            left = i + 1;
            right = nums.length - 1;
            
            // 去重,为什么采用 nums[i-1] == nums[i],存在[0,0,0]这种情况
            if (i > 0 && nums[i-1] == nums[i]){
    
    
                continue;
            }
            // 循环内部左右指针遍历可能出现的结果。
            while (left < right){
    
    
                int result = nums[i] + nums[left] + nums[right];
                if (result > 0){
    
    
                    right--;
                }else if (result < 0){
    
    
                    left++;
                }else {
    
    
                    // 添加符合要求的数据到 集合中
                    resultList.add(Arrays.asList(nums[i],nums[left],nums[right]));
                    // 左边数据去重, nums[left] == nums[left+1]
                    while (left < right && nums[left] == nums[left+1]){
    
    
                        left++;
                    }
                    // 右边数据去重, nums[right] == nums[right-1]
                    while (left < right && nums[right] == nums[right-1]){
    
    
                        right--;
                    }
                    // 获取符合要求的数据后,左边++,右边 --
                    left++;
                    right--;
                }
                
                
            }
        }
        return resultList;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

  1. 给定两个字符串,str1 = They are students,和 str2 = aeiou,移除str1中和str2相同的字符。
import java.util.HashMap;
import java.util.Scanner;
public class Main {
    
    
    public static void main(String[] args) {
    
    
        
        Scanner in = new Scanner(System.in);
        String[] strarr = new String[2];
        int  count = 0;
        while (in.hasNextLine() && count < 2){
    
    
            strarr[count++] = in.nextLine();
        }
        String oldStr  = strarr[0];
        String removeStr = strarr[1];
        HashMap<Character,Integer> remMap = new HashMap<>();
        
        for (int i = 0; i < removeStr.length(); i++ ){
    
    
            remMap.put(removeStr.charAt(i),0);
        }
        
        int slow = 0;
        int fast = 0;
        char[] chars = oldStr.toCharArray();
        while (fast < oldStr.length()){
    
    
            Integer integer = remMap.get(chars[fast]);
            if (integer!= null && integer == 0){
    
    
                fast++;
            }else {
    
    
                chars[slow] = chars[fast];
                slow++;
                fast++;
            }
        }
        oldStr = String.valueOf(chars).substring(0,slow);
        System.out.println(oldStr);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_42102911/article/details/131430058