您好,欢迎来到汇智旅游网。
搜索
您的当前位置:首页915. 分割数组

915. 分割数组

来源:汇智旅游网

一、题目链接

二、解题思路

每次存左边的最大值(表示分割后左边数组的最大值),然后每次保留道当前位置的最大值。如果小于当前左侧的最大值,则替换左侧最大值。

三、代码

class Solution(object):
    def partitionDisjoint(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        cur_max = left_max = nums[0]
        left_pos = 0
        for i in range(1, n - 1):
            cur_max = max(cur_max, nums[i])
            if nums[i] < left_max:
                left_max, left_pos = cur_max, i
        return left_pos + 1

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- hzar.cn 版权所有 赣ICP备2024042791号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务