import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 计算旺仔哥哥在地铁上的最长停留时间
* @param t int整型一维数组 序列 t,表示地铁在相邻两站之间的用时
* @param s int整型一维数组 序列 s,表示地铁在每一站的停靠时间
* @param x int整型 旺仔哥哥想从第 x 站出发
* @param y int整型 旺仔哥哥想坐到第 y 站
* @return int整型
*/
public int countLongestSubwayTime (int[] t, int[] s, int x, int y) {
// write code here
int time=0;
for (int i = x-1; i < y; i++) {
time+=s[i];
}
for (int i = x-1; i < y-1; i++) {
time+=t[i];
}
return time;
}
}
这题需要注意一下索引,尤其是对t数组求和时,索引为3实际上代表的意思是从第四站坐车到第五站,所以测试用例那个对应的最大应该是y-2



京公网安备 11010502036488号