Skip to content

Commit bab0ae5

Browse files
authored
Update 1021-best-sightseeing-pair.js
1 parent 3ebe48c commit bab0ae5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1021-best-sightseeing-pair.js

+19
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,22 @@ const maxScoreSightseeingPair = function(A) {
1010
}
1111
return res;
1212
};
13+
14+
15+
// another
16+
17+
/**
18+
* @param {number[]} A
19+
* @return {number}
20+
*/
21+
const maxScoreSightseeingPair = function(A) {
22+
let ans =A[0];
23+
let prevBestIdx =0;
24+
for(let j=1;j<A.length;j++){
25+
ans = Math.max(ans, A[prevBestIdx]+prevBestIdx+A[j]-j);
26+
if(A[prevBestIdx ]+prevBestIdx <A[j]+j){
27+
prevBestIdx =j;
28+
}
29+
}
30+
return ans;
31+
};

0 commit comments

Comments
 (0)