【leetcode】欲張りアルゴリズム1338 455
1006 ワード
1338配列サイズ半減
class Solution:
def minSetSize(self, arr: List[int]) -> int:
count_total = 0
for i,count in enumerate(sorted(collections.Counter(arr).values(),reverse = True)):
count_total += count
if count_total >= len(arr) / 2:
return i + 1
455.ビスケットを配る
class Solution:
def findContentChildren(self, g, s):
g.sort(reverse = True)
s.sort(reverse = True)
i = j = 0
while i < len(g) and j < len(s):
if g[i] <= s[j]:
j += 1
i += 1
return j