爱奇艺笔试
爱奇艺笔试 用的是赛码网,自己一不小心,交卷了,心痛啊!
1.SQL语句
select demand_id, count(demand_id) from task group by demand_id having count(demand_id) >= 2;
2.滑动窗口的问题
package QiYi; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()){ String line = sc.nextLine(); String[] split = line.split("\\,"); int[] arr = new int[split.length]; for(int i = 0;i<split.length-1;i++){ arr[i] = Integer.parseInt(split[i]); } String end = split[split.length-1]; String[] res = end.split("\\:"); arr[split.length-1] = Integer.parseInt(res[0]); int k = Integer.parseInt(res[1]); LinkedList<Integer> window = new LinkedList<>(); ArrayList<Double> temp = new ArrayList<>(); for(int i = 0;i<arr.length;i++){ if(i<k-1){ window.addLast(arr[i]); continue; } window.add(arr[i]); temp.add(ave(window)); window.pollFirst(); } double result = 0; for(int i= 0;i<temp.size()-1;i++){ double te = temp.get(i+1) - temp.get(i); result = Math.max(result,te/temp.get(i)); } System.out.printf("%.2f%%",result*100); } } private static double ave(LinkedList<Integer> window) { double sum = 0; for(int i = 0;i<window.size();i++){ sum += window.get(i); } return sum/window.size(); } }
3.力扣原图 力扣:1488. 避免洪水泛滥。
下面是参考的题解
class Solution { public int[] avoidFlood(int[] rains) { int n = rains.length; // 记录装满水的湖泊,key号湖泊在第val天装满 Map<Integer, Integer> map = new HashMap<>(); // 记录为 0 的索引,最后一次可以抽水的时机在队列尾 LinkedList<Integer> q = new LinkedList<>(); int[] ans = new int[n]; for (int i = 0; i < n; i++) { if (rains[i] == 0) { /* 不下雨 */ q.offer(i); ans[i] = 1; } else { /* 下雨:如果 rains[i] > 0 ,那么ans[i] = -1 */ ans[i] = -1; if (!map.containsKey(rains[i])){ // 湖泊本来就没水,加水 map.put(rains[i], i); } else { // 湖泊本来有水,要抽水 if (q.isEmpty() || q.getLast() < map.get(rains[i])){ // 没得抽(要保证雨下在抽水之前) return new int[]{}; } int idx = -1; // 遍历队列,找到第一个可以抽水的日子(选最近日子的会有问题) for (int j = 0; j < q.size(); j++) { if (q.get(j) > map.get(rains[i])) { idx = q.get(j); q.remove(j); break; } } // 更新key号湖泊在第val天装满 map.put(rains[i], i); ans[idx] = rains[i]; } } } return ans; } }
4.线程池(不会,有大佬会的,求教)