MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_1014/Solution.java:11–27  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2020/06/18 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12
13 public int maxScoreSightseeingPair(int[] A) {
14 int ans = 0, cur = A[0] + 0;
15 for (int j = 1; j < A.length; j++) {
16 ans = Math.max(ans, cur + A[j] - j); // 计算当前最大得分
17 cur = Math.max(cur, A[j] + j); // 更新最大的 A[i] + i
18 }
19 return ans;
20 }
21
22 public static void main(String[] args) {
23 Solution solution = new Solution();
24 int[] A = new int[]{8, 1, 5, 2, 6};
25 System.out.println(solution.maxScoreSightseeingPair(A));
26 }
27}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected