Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Created March 29, 2019 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/4ebabdcb84c705631b8e33982741baab to your computer and use it in GitHub Desktop.
Save fpdjsns/4ebabdcb84c705631b8e33982741baab to your computer and use it in GitHub Desktop.
[leetcode] 1021. Best Sightseeing Pair : https://leetcode.com/problems/best-sightseeing-pair/
class Solution {
public:
int maxScoreSightseeingPair(vector<int>& A) {
int l = 0, r = 0;
int answer = -1e5;
for(int r=1; r<A.size(); r++){
answer =max(answer, A[l] + A[r] + l - r);
if(A[l] <= A[r] + r - l)
l = r;
}
return answer;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment