[Leetcode] 每日两题 1996 916 -day85

1996. 游戏中弱角色的数量

由于是比较两个值是否都大于,所以可以按照攻击值降序排序,

对于排序后遍历的每个元素的攻击值都是存在存在比他大的,所以只需维护一个防御值的当前最大就行,若当前元素的防御值小于当前最大,那么弱角色+1

class Solution:
    def numberOfWeakCharacters(self, properties: List[List[int]]) -> int:
        res = 0 
        properties = sorted(properties,key= lambda x:(-x[0],x[1]))
        maxt = 0
        for prop in properties:
            if maxt > prop[1]:
                res +=1
            else :
                maxt = prop[1]
        return res
[916. 单词子集](https://leetcode-cn.com/problems/find-first-palindromic-string-in-the-array/)

首先 记录 word2 列表 所有单词的 字母并集,

对于word1 中的单词 ,判断是否大于该并集

class Solution:
    def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:

        wdic = defaultdict(int)
        res = []
        for word in words2:
            coun = Counter(word)
            for key in coun:
                if coun[key] > wdic.get(key,0):
                    wdic[key] =coun[key]
        for word in words1:
            coun = Counter(word)
            flag =1
            for key in wdic:
                if coun[key] < wdic[key]:
                    flag =0
                    break
            if flag:
                res.append(word)
        #print(wdic)
            #print(a['e'])
        return res

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值