Java8 Stream 计算数组最大值、最小值

最大值(整数数组):

Arrays.stream(A).max().getAsInt()

int[] A = {6,7,8,2,1,3,4,5};
int maxVal = Arrays.stream(A).max().getAsInt();

最小值(整数数组):

Arrays.stream(A).min().getAsInt()

int[] A = {6,7,8,2,1,3,4,5};
int minVal = Arrays.stream(A).min().getAsInt();

 

[LeetCode]Minimum Number of Refueling Stops

题目描述:

LeetCode 871. Minimum Number of Refueling Stops

A car travels from a starting position to a destination which is target miles east of the starting position.

Along the way, there are gas stations.  Each station[i] represents a gas station ...

继续阅读