第 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]
标签:周赛,276,int,minstep,questions,maxDoubles,type,target 来源: https://blog.csdn.net/qq_44833392/article/details/122521822