Leetcode刷题(八)

一、1374. 生成每种字符都是奇数个的字符串

代码:

class Solution:
    def generateTheString(self, n: int) -> str:
        ans = ''
        if n %2!=0:
            for i in range(n):
                ans+="a"
            return ans
        else:
            for i in range(n-1):
                ans+="a"
            ans+="b"    
            return ans

二、1365. 有多少小于当前数字的数字

代码:

class Solution:
    def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
        ans = []
        for i in range(len(nums)):
            cnt = 0
            for j in range(len(nums)):
                if nums[i]>nums[j] and i!=j:
                    cnt+=1
            ans.append(cnt)
        return ans

三、1346. 检查整数及其两倍数是否存在

代码:

class Solution:
    def checkIfExist(self, arr: List[int]) -> bool:
        arr.sort()
        for i ,x in enumerate(arr):
            if x*2 in arr and arr.index(x*2) != i:
                return True
        return False

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值