网易互娱笔试!
有大佬来个递增二叉树的java代码吗!
看到很多人都说咖啡的题0%.我贴个咖啡的代码吧
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int i = 0; i < T; i++) {
int K = in.nextInt();
int M = in.nextInt();
int l = 1;
int r = 0;
int count = 0;
for(int j = 0; j < M; j++) {
int temp= in.nextInt();
count ++;
r = temp - K - 1;
if(r >= l) {
count = count + (r - l)/(K + 1) + 1;
}
l = temp + K + 1;
}
if(l <= 30) {
count = count + (30 - l)/(K + 1) + 1;
}
System.out.println(count);
}
}
360集团公司氛围 350人发布