leetcode-5.12[263. 丑数、884. 两句话中的不常见单词、929. 独特的电子邮件地址](python实现)

题目1

在这里插入图片描述

题解1

class Solution:
    def isUgly(self, num: int) -> bool:
        """
            贪心算法
        """
        #     if num < 1:
        #         return False
        #     while num % 2 == 0:
        #         num /= 2
        #     while num % 3 == 0:
        #         num /= 3
        #     while num % 5 == 0:
        #         num /= 5
        #    return num == 1


        while (num > 1) and (num%2==0 or num%3==0 or num%5==0):
            if num%2 == 0:
               num /= 2
            if num%3 == 0:
                num /= 3
            if num%5 == 0:
                num /= 5
        return num == 1

题目2

在这里插入图片描述

附上题目链接

题解2

class Solution:
    def uncommonFromSentences(self, A: str, B: str) -> List[str]:
        from collections import Counter
        # 过滤出现多次(>1)的单词
        countA = Counter(A.split())
        countB = Counter(B.split())
        setA = set([key for key in countA if countA[key] > 1])
        setB = set([key for key in countB if countB[key] > 1])
        # 求差集
        count = set(A.split())^set(B.split())
        # 过滤在次数超过两次的单词
        count = count - setA - setB
        return count

附上题目链接

题目3

在这里插入图片描述

题解3

class Solution:
    def numUniqueEmails(self, emails: List[str]) -> int:
        res=set()
        for email in emails:
            # 分隔本地名称和域名
            local,domain=email.split('@')

            idx=local.find('+')
            if idx==-1:
                idx=len(local)
            # 如果有加号去掉+之前的. ,否则去掉整个本地名称的.
            ls=local[:idx].split('.')
            res.add(''.join(ls)+'@'+domain)

        return len(res)

附上题目链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值