leecode刷题:1800. 最大升序子数组和

in hive-180932 •  4 months ago 

image.png

这题是周赛的题目。

我的思路很简单,按升序累加数字,当下一个数字小于或者等于的时候,把结果返回到一个新数组去,并重置再来。

class Solution:
    def maxAscendingSum(self, nums: List[int]) -> int:
        all=[]
        start=0
        for i in range(len(nums)):
            start+=nums[i]
            try:
                if nums[i] - nums[i + 1] >= 0:
                    all.append(start)
                    start=0
            except:
                all.append(start)
        return max(all)

用了try,except,感觉是有点取巧的写法。

image.png

速度还行

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

拍拍

Hello there,
I hope you can help me out. I tried to register a user at https://follow.steems.top/ , but somehow, I didn't copy correctly the password given me upon registration. So, when I tried to change the password or log in with it, I couldn't do so. I tried to revoke access to steems.top in order to register once again, but I only receive a message, that the user has already been created. As a result, I am unable to log in with my account.

Is there a way to fix this?