leetcode1282

 1 class Solution:
 2     def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]:
 3         dic = {}
 4         n = len(groupSizes)
 5         for i in range(n):
 6             if groupSizes[i] not in dic:
 7                 dic[groupSizes[i]] = [i]
 8             else:
 9                 dic[groupSizes[i]].append(i)
10         res = []
11         for k,v indic.items ():
 12 is              #k: each of several, v set
 13 is              TEMP = []
 14              for J in Range (len (V)):
 15                  temp.append (V [J])
 16                  IF len (TEMP) == K:
 . 17                      res.append (TEMP [:])
 18 is                      temp.clear ()
 . 19          return RES

Hash thought, each record set of elements corresponding to the size of the dic.

And then grouped according to the size of the size of each subset contains size elements.

Guess you like

Origin www.cnblogs.com/asenyang/p/12005115.html