标签:leetcode
Question:
Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j].
// O(n) public int maxDistance(int[] A) { // Assumptions... int local = Integer.MIN_VALUE; int global = Integer.MIN_VALUE; for (int i = 1 ; i < A.length ; i ++) { if (A[i] > A[i - 1]) { local += 1; } else { local = 0; } global = Math.max(global, local); } return global; }
[LeetCode] A Distance Maximizing Problem
标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1605509