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
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)))
# 这里采用滑动窗口,当滑动窗口达到一个最大值后,窗口一直前进
# 当窗口内记载的出现次数最大字符大于上一次的出现最大次数字符时,窗口长度增加
# 否则,窗口保持原来长度前进一个单位
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