1014. 最佳观光组合
a[i]+a[j]-(j-i)=a[i]+i-a[j]-j
j要比i大,enmerate 使数组变成类似于字典
class Solution(object): def maxScoreSightseeingPair(self, A): mx=float('-inf') zong=0 for i,val in enumerate(A): zong=max(zong,val-i+mx) mx=max(mx,val+i) return zong
a[i]+a[j]-(j-i)=a[i]+i-a[j]-j
j要比i大,enmerate 使数组变成类似于字典
class Solution(object): def maxScoreSightseeingPair(self, A): mx=float('-inf') zong=0 for i,val in enumerate(A): zong=max(zong,val-i+mx) mx=max(mx,val+i) return zong