力扣第 263场周赛

5902. 检查句子中的数字是否递增

python就是好用,split()划分+dic计数

1
2
3
4
5
6
7
8
9
10
11
12
class Solution:
def areNumbersAscending(self, s: str) -> bool:
dic={str(i):1 for i in range(101)}
res=0
for x in s.split():
if dic.get(x):
if res<int(x):
res=int(x)
else:
return False

return True

5903. 简易银行系统

从没遇到过这么简单的模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Bank:

def __init__(self, balance: List[int]):
self.m=[*balance]
self.n=len(self.m)


def transfer(self, account1: int, account2: int, money: int) -> bool:
account1-=1
account2-=1
if account1<0 or account1>=self.n or account2<0 or account2>=self.n:return False
if self.m[account1]>=money:
self.m[account1]-=money
self.m[account2]+=money
return True
else:
return False


def deposit(self, account: int, money: int) -> bool:
account-=1
if account<0 or account>=self.n:return False
self.m[account]+=money
return True


def withdraw(self, account: int, money: int) -> bool:
account-=1
if account<0 or account>=self.n:return False
if self.m[account]>=money:
self.m[account]-=money
return True
else:
return False



# Your Bank object will be instantiated and called as such:
# obj = Bank(balance)
# param_1 = obj.transfer(account1,account2,money)
# param_2 = obj.deposit(account,money)
# param_3 = obj.withdraw(account,money)

5904. 统计按位或能得到最大值的子集数目

史上最简单T3之一,combination->过

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution:
def countMaxOrSubsets(self, nums: List[int]) -> int:
def findxor(nums):
n=len(nums)
pre=nums[0]
for i in range(1,n):
pre|=nums[i]
return pre

dic=defaultdict(int)
n=len(nums)
res=-1
for a in range(n):
for i in combinations(nums, a+1):
tmp=findxor(i)
res=max(res,tmp)
dic[tmp]+=1
return dic[res]
不要打赏,只求关注呀QAQ