HTMLify

LeetCode - Convert an Array Into a 2D Array With Conditions - Python
Views: 135 | Author: abh
class Solution:
    def findMatrix(self, nums: List[int]) -> List[List[int]]:
        mat = []
        for n in nums:
            put = False
            for row in mat:
                if not n in row:
                    row.append(n)
                    put = True
                    break
            if not put:
                mat.append([n])
        return mat

Comments