[LeetCode] A Distance Maximizing Problem
2015-01-19 09:42
1601 查看
Question:
Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j].
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; }
相关文章推荐
- My Solution to A Distance Maximizing Problem
- A Distance Maximizing Problem
- 算法设计Week8 LeetCode Algorithms Problem #198 House Robber
- uva 729 - The Hamming Distance Problem(全排列)
- leetcode 461. Hamming Distance
- Leetcode Problem difficulty level and frequency table(zz)
- LeetCode 72. Edit Distance(编辑距离)
- LeetCode-Shortest Word Distance III
- LeetCode 624. Maximum Distance in Arrays (在数组中的最大距离)$
- <medium>LeetCode Problem -- 565. Array Nesting
- [LeetCode] The Skyline Problem 天际线问题
- <easy>LeetCode Problem -- 747. Largest Number At Least Twice of Others
- [LeetCode243]Shortest Word Distance
- LeetCode 72. Edit Distance
- LeetCode-One Edit Distance
- LeetCode 72. Edit Distance
- LeetCode Two Point & Array Problem 两点问题汇总
- uva 729 - The Hamming Distance Problem
- LeetCode.Problem 1 Two Sum
- Dynamic Programing -- Leetcode problem 338. Counting Bits