【算法】力扣第 263 场周赛

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

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

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. 简易银行系统

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

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->过

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]

评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

可可卷

不要看到我~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值