给定一个双精度数组
1.0 2.0 3.0 ... 10.0
输出
filter(3,7) should produce 3.0,4.0,5.0,6.0,7.0
filter(5,7.5) should produce 5.0,6.0,7.0,8.0
filter(6.6,6.7) should produce 6.0,7.0
基于一种filter
方法
public List<Double> filter(double start, double end){
List<Double> list = Arrays.asList(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0);
List<Double> resultList = new ArrayList<Double>();
//search in list for elements such that it includes the lower bounds and upper bound of search
//i.e. 6.6 should also include 6.0 and 7.0 from the array.
return resultList;
}
这看起来很简单,但我一直无法想出一个令我满意的解决方案,因此提出了这个问题。任何帮助将不胜感激。