y****3 发帖数: 131 | 1
public class Monotonic {
enum type {
increasing, decreasing, undefined
}
public boolean isMonotonic(int[] input) {
if (input == null || input.length <= 1)
return true;
type mono_type = type.undefined;
for (int i = 0; i < input.length - 1; i++) {
if (input[i] > input[i+1]) {
if (mono_type == type.increasing) return false;
mono_type = type.decreasing;
}
else if (input[i] < i... 阅读全帖 |
|