[剑指offer] JAVA版题解 面试题63

[剑指offer] JAVA版题解 面试题63_第1张图片

代码演示:

package swordfingeroffer;

/**
 * 

Description:

* * @author 罗志远 * @version 1.0 * @name InterviewQuestion63 * @date 2020-07-05 17:34 */
public class InterviewQuestion63 { public int maxDiff(int[] number) { if (null == number || number.length < 2) { throw new IllegalArgumentException("参数不正确!"); } int min = number[0]; int maxDiff = number[1]; for (int i = 2; i < number.length;i ++) { if (number[i - 1] < min) { min = number[i - 1]; } int currentMax = number[i] - min; if (currentMax > maxDiff) { maxDiff = currentMax; } } return maxDiff; } }

你可能感兴趣的:(剑指offer)