题目地址 (opens new window)
解题代码
class Solution { public int maxScoreSightseeingPair(int[] A) { int ans = 0, mx = A[0] + 0; for (int i = 1; i < A.length; i++) { ans = Math.max(ans, mx + A[i] - i); // 边遍历边维护 mx = Math.max(mx, A[i] + i); } return ans; } }
← LeetCode 无重复字符的最长字串 LeetCode 最小基因变化 →