We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定正整数数组 A,A[i] 表示第 i 个观光景点的评分,并且两个景点 i 和 j 之间的距离为 j - i。
A
A[i]
i
j
j - i
一对景点(i < j)组成的观光组合的得分为(A[i] + A[j] + i - j):景点的评分之和减去它们两者之间的距离。
i < j
A[i] + A[j] + i - j
返回一对观光景点能取得的最高分。
Input: [8,1,5,2,6] Output: 11 Explanation: i = 0, j = 2, A[i] + A[j] + i - j = 8 + 5 + 0 - 2 = 11
2 <= A.length <= 50000
1 <= A[i] <= 1000
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} A * @return {number} */ var maxScoreSightseeingPair = function(A) { let result = -Infinity; let maxScoreSightseeingPoint = A[0] + 0; for (let i = 1; i < A.length; i++) { result = Math.max(maxScoreSightseeingPoint + A[i] - i, result); maxScoreSightseeingPoint = Math.max(A[i] + i, maxScoreSightseeingPoint); } return result; };
function maxScoreSightseeingPair(A: number[]): number { let result = -Infinity; let maxScoreSightseeingPoint = A[0] + 0; for (let i = 1; i < A.length; i++) { result = Math.max(maxScoreSightseeingPoint + A[i] - i, result); maxScoreSightseeingPoint = Math.max(A[i] + i, maxScoreSightseeingPoint); } return result; };
Sorry, something went wrong.
No branches or pull requests
1014. Best Sightseeing Pair
给定正整数数组
A
,A[i]
表示第i
个观光景点的评分,并且两个景点i
和j
之间的距离为j - i
。一对景点(
i < j
)组成的观光组合的得分为(A[i] + A[j] + i - j
):景点的评分之和减去它们两者之间的距离。返回一对观光景点能取得的最高分。
Example
Note
2 <= A.length <= 50000
1 <= A[i] <= 1000
The text was updated successfully, but these errors were encountered: