728x90
https://leetcode.com/problems/convert-an-array-into-a-2d-array-with-conditions
class Solution:
def findMatrix(self, nums: List[int]) -> List[List[int]]:
result = []
nums_dic = {}
for n in nums:
nums_dic[n] = nums_dic.get(n, 0) + 1
for i in range(0, max(nums_dic.values())):
result.append([])
for key, value in nums_dic.items():
for i in range(0, value):
result[i].append(key)
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 535. Encode and Decode TinyURL (0) | 2024.02.18 |
---|---|
[Leetcode] 1365. How Many Numbers Are Smaller Than the Current Number (0) | 2024.02.09 |
[Leetcode] 1282. Group the People Given the Group Size They Belong To (0) | 2024.02.08 |
[Leetcode] 771. Jewels and Stones (0) | 2024.02.07 |
[Leetcode] 1512. Number of Good Pairs (0) | 2024.02.07 |