File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,088 LeetCode solutions in JavaScript
1
+ # 1,089 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
822
822
1011|[ Capacity To Ship Packages Within D Days] ( ./solutions/1011-capacity-to-ship-packages-within-d-days.js ) |Medium|
823
823
1012|[ Numbers With Repeated Digits] ( ./solutions/1012-numbers-with-repeated-digits.js ) |Hard|
824
824
1013|[ Partition Array Into Three Parts With Equal Sum] ( ./solutions/1013-partition-array-into-three-parts-with-equal-sum.js ) |Easy|
825
+ 1014|[ Best Sightseeing Pair] ( ./solutions/1014-best-sightseeing-pair.js ) |Medium|
825
826
1022|[ Sum of Root To Leaf Binary Numbers] ( ./solutions/1022-sum-of-root-to-leaf-binary-numbers.js ) |Easy|
826
827
1023|[ Camelcase Matching] ( ./solutions/1023-camelcase-matching.js ) |Medium|
827
828
1028|[ Recover a Tree From Preorder Traversal] ( ./solutions/1028-recover-a-tree-from-preorder-traversal.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1014. Best Sightseeing Pair
3
+ * https://leetcode.com/problems/best-sightseeing-pair/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array values where values[i] represents the value of the ith sightseeing
7
+ * spot. Two sightseeing spots i and j have a distance j - i between them.
8
+ *
9
+ * The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the
10
+ * values of the sightseeing spots, minus the distance between them.
11
+ *
12
+ * Return the maximum score of a pair of sightseeing spots.
13
+ */
14
+
15
+ /**
16
+ * @param {number[] } values
17
+ * @return {number }
18
+ */
19
+ var maxScoreSightseeingPair = function ( values ) {
20
+ let maxLeft = values [ 0 ] ;
21
+ let result = 0 ;
22
+
23
+ for ( let j = 1 ; j < values . length ; j ++ ) {
24
+ result = Math . max ( result , maxLeft + values [ j ] - j ) ;
25
+ maxLeft = Math . max ( maxLeft , values [ j ] + j ) ;
26
+ }
27
+
28
+ return result ;
29
+ } ;
You can’t perform that action at this time.
0 commit comments