7.27笔记

406. 根据身高重建队列

class Solution(object):
    def reconstructQueue(self, people):
        a = sorted(people,key = lambda x: (-x[0],x[1])) #按照身高降序k升序进行排列
        res = []
        for each in a:
            res.insert(each[1],each)        #按照k值进行插入
        return res

423. 从英文中重建数字

class Solution(object):
    def originalDigits(self, s):
        """
        :type s: str
        :rtype: str
        """
        n0 = s.count('z')
        n2 = s.count('w')
        n8 = s.count('g')
        n6 = s.count('x')
        n3 = s.count('t') - n2 - n8
        n4 = s.count('r') - n3 - n0
        n7 = s.count('s') - n6
        n1 = s.count('o') - n4 - n2 - n0
        n5 = s.count('v') - n7
        n9 = s.count('i') - n8 - n6 - n5
        res = (n0,n1,n2,n3,n4,n5,n6,n7,n8,n9)
        return "".join((str(i)*n for i,n in enumerate(res)))
        

424. 替换后的最长重复字符

# 这里采用滑动窗口,当滑动窗口达到一个最大值后,窗口一直前进
# 当窗口内记载的出现次数最大字符大于上一次的出现最大次数字符时,窗口长度增加
# 否则,窗口保持原来长度前进一个单位
class Solution(object):
    def characterReplacement(self, s, k):
        res,m,max1 = 0,collections.Counter(),0
        for i in range(len(s)):
            m[s[i]] += 1
            max1 = max(max1,m[s[i]])
            if res - max1 < k:
                res += 1
            else:
                m[s[i-res]] -= 1
        return res
    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值