题目
第274场周赛
代码1
class Solution(object):
def checkString(self, s):
"""
:type s: str
:rtype: bool
"""
if 'a' not in s:
return True
flag = True
for i in range(len(s)):
if s[i] == 'a':
if flag == False:
return flag
continue
else:
flag = False
return True
运行结果1
代码2
class Solution(object):
def numberOfBeams(self, bank):
"""
:type bank: List[str]
:rtype: int
"""
hang1 = 0
startHang = 0
res = 0
for i in range(len(bank)):
for j in range(len(bank[i])):
if bank[i][j] == '0':
continue
else:
hang1 += 1
if hang1!=0:
startHang = i+1
break
hang2 = 0
for i in range(startHang,len(bank)):
for j in range(len(bank[i])):
if bank[i][j] == '0':
continue
else:
hang2 += 1
if hang2 != 0:
res +=hang1*hang2
hang1 = hang2
hang2 = 0
return res
运行结果2
代码3
class Solution(object):
def asteroidsDestroyed(self, mass, asteroids):
"""
:type mass: int
:type asteroids: List[int]
:rtype: bool
"""
asteroids.sort()
for i in range(len(asteroids)):
if mass>=asteroids[-1]:
break
if mass>=asteroids[i]:
mass+=asteroids[i]
else:
return False
return True