一、题目链接
二、解题思路
每次存左边的最大值(表示分割后左边数组的最大值),然后每次保留道当前位置的最大值。如果小于当前左侧的最大值,则替换左侧最大值。
三、代码
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