第 276 场周赛

文章目录


第 276 场周赛

代码1

class Solution(object):
    def divideString(self, s, k, fill):
        """
        :type s: str
        :type k: int
        :type fill: str
        :rtype: List[str]
        """
        l = []
        temp = ""
        for i in range(len(s)):
            if len(temp)<k:
                temp+=s[i]
            else:
                l.append(temp)
                temp = s[i]
        if temp:
            temp+=(k-len(temp))*fill
            l.append(temp)
        return l

代码2

class Solution(object):
    def minMoves(self, target, maxDoubles):
        """
        :type target: int
        :type maxDoubles: int
        :rtype: int
        """
  
        minstep  = 0
        while target!=1:
            if maxDoubles == 0:
                minstep+=target-1
                break
            if target %2==0 and maxDoubles:
                target/=2
                maxDoubles-=1
                minstep+=1
            else:
                target-=1
                minstep+=1
        return minstep

代码3

class Solution(object):
    def mostPoints(self, questions):
        """
        :type questions: List[List[int]]
        :rtype: int
        """
        if len(questions) == 1:
            return questions[0][0]

        dp = [0]*(len(questions)+1)
        n = len(questions)
        for i in range(n-1,-1,-1):
            q = questions[i]
            j = i+q[1]+1
            dp[i] = max(dp[i+1],q[0]+(dp[j] if j<n else 0))

        return dp[0]
上一篇:单周赛 2022.1.16 题解汇总


下一篇:LeetCode 第 276 场周赛总结