Created
March 29, 2019 08:30
-
-
Save fpdjsns/4ebabdcb84c705631b8e33982741baab to your computer and use it in GitHub Desktop.
[leetcode] 1021. Best Sightseeing Pair : https://leetcode.com/problems/best-sightseeing-pair/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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