// 不知道怎么回事,这样写就会报错
/*
./Solution.java:11: error: cannot find symbol
list.add(max);
^
symbol: variable max
location: class Solution
Note: ./Solution.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
/
import java.util.
;
public class Solution {
ArrayList<integer> list = new ArrayList();
public ArrayList<integer> maxInWindows(int [] num, int size)
{
if(size > num.length || size == 0) return list;
for(int i = 0 ;i<num.length-size+1;i++){
for(int j = i;j<i+size-1 && j+1 <num.length; j++){
int max = (num[j] >num[j+1])? num[j]: num[j+1];
}
list.add(max);
}
return list;
}
}
//然后这样写就可以 有点搞不懂 求大佬赐教
import java.util.*;
public class Solution {
ArrayList<integer> list = new ArrayList();
public ArrayList<integer> maxInWindows(int [] num, int size)
{
if(size > num.length || size == 0) return list;
for(int i = 0 ;i<num.length-size+1;i++){
int max = num[i];
for(int j = i;j<i+size-1 && j+1 <num.length; j++){
max = (max >num[j+1])? max: num[j+1];
}
list.add(max);
}
return list;
}
}</integer></integer></integer></integer>