1014. 最佳观光组合

1014. 最佳观光组合

  • 原题链接:
  • 完成情况:
  • 解题思路:
  • 参考代码:

原题链接:

1014. 最佳观光组合

https://editor.csdn.net/md/?not_checkout=1&spm=1000.2115.3001.5352

完成情况:

1014. 最佳观光组合_第1张图片

解题思路:

1014. 最佳观光组合_第2张图片

参考代码:

package LeetCode中等题;

public class __1014最佳观光组合 {
    /**
     *
     * @param values
     * @return
     */
    public int maxScoreSightseeingPair(int[] values) {
        int res = 0,max = values[0] + 0;
        for (int j=1;j< values.length;j++){
            res = Math.max(res,max + values[j] - j);
            //边遍历,边维护
            max = Math.max(max,values[j]+j);
        }
        return res;
    }
}

你可能感兴趣的:(算法知识,#,LeetCode题解,java学习,java,开发语言,算法,字符串,数据结构)