巨人网络笔试简单题解
第一题
System.out.println("A获胜6次,B获胜4次");
不知道是不是后面随机数种子在匹配,没敢二次提交,怕被reject了。
第二题
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = in.nextInt();
}
in.nextLine();
int value = in.nextInt();
Deque<Integer> q1 = new ArrayDeque<>(); // da
Deque<Integer> q2 = new ArrayDeque<>(); // xiao
q1.add(0);
q2.add(0);
int res = 0;
int mx = 0;
int left = 0;
for(int right=1;right<n;right++){
while(!q1.isEmpty() && a[q1.peekLast()]<=a[right]){
q1.pollLast();
}
q1.offerLast(right);
while(!q2.isEmpty() && a[q2.peekLast()]>=a[right]){
q2.pollLast();
}
q2.offerLast(right);
while(Math.abs(a[q1.peekFirst()]-a[q2.peekFirst()])>value){
left++;
while(q1.peekFirst()<left){
q1.pollFirst();
}
while(q2.peekFirst()<left){
q2.pollFirst();
}
}
mx = Math.max(mx,right-left+1);
}
System.out.print(mx>1?mx:0);
}
}
滑动窗口最大最小值,一开始题目实在读不懂,用了排序、用了贪心,发现最大实力差距是这个窗口的,第二个案例说实话挺良心的,但是不知道为什么只过了87.5,还剩一个样例过不了,没有数据不会调试了,直接跑路了,不知道有没有佬提点一下
#笔试##巨人网络##巨人网络笔试讨论##巨人网络校招##实习#
查看6道真题和解析