#69. 数组最大最小值之差

    ID: 69 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp3一维数组循环结构

数组最大最小值之差

Array Range

Background

Dawei is teaching the basics of arrays. To help students better understand array properties, he posed a simple problem, asking everyone to calculate the difference between the maximum and minimum values in an array.

Problem Description

Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Note: the built-in Math.min(v1, v2) and Math.max(v1, v2) methods return the smaller or larger of two values.

Input Format

Input is given from standard input in the following format.

A single line containing multiple integers, representing the elements of the array. Elements are separated by spaces.

Output Format

Output is printed to standard output in the following format.

A single integer, representing the difference between the maximum and minimum values in the array.

Sample

10 3 5 6
7
7 2 10 9
8
2 10 7 2
8

Sample Explanation

For the first sample, the array is [10,3,5,6][10, 3, 5, 6]. The maximum value is 1010, and the minimum value is 33. Their difference is 103=710 - 3 = 7.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.