Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueEror Square submatrices #301

Open
sgmmd opened this issue Oct 29, 2024 · 1 comment
Open

ValueEror Square submatrices #301

sgmmd opened this issue Oct 29, 2024 · 1 comment

Comments

@sgmmd
Copy link

sgmmd commented Oct 29, 2024

when i run this code i get an runtime error and it writes runtime:0ms

class Solution:
    def countSquares(self, matrix: list[list[int]]) -> int:
        self.MATRIXWIDTH,self.MATRIXHIGHT = len(matrix[0]),len(matrix)
        maximumBoundary = [-1,-1]
        boundaries= []
        for y,lines in enumerate(matrix):
            for x,cols in enumerate(lines):

                if cols == 0:

                    if x > maximumBoundary[0]:maximumBoundary[0] = x
                    if y > maximumBoundary[1]: maximumBoundary[1] = y
                    boundaries.append((x,y))

        amount = []

            # get the closest zero if the zero isn't pass the current position
        closestBoundary = lambda x, y: min(
            (max(bounds[0] - x, bounds[1] - y) for bounds in boundaries
             if bounds[0] >= x and bounds[1] >= y))

        value = 0
        for y,lines in enumerate(matrix):
            for x,cols in enumerate(lines):
                value=0
                if cols==0:continue
                if x > maximumBoundary[0] or y > maximumBoundary[1]:
                    value = min(self.MATRIXWIDTH-x,self.MATRIXHIGHT-y)
                else:

                    value = min(closestBoundary(x,y),min(self.MATRIXWIDTH-x,self.MATRIXHIGHT-y))

                amount.append(value)


        return sum(amount)

ValueError: min() arg is an empty sequence ^^^^ closestBoundry = lambda x, y: min( Line 19 in <lambda> (Solution.py) ^^^^^^^^^^^^^^^^^^^ print('hi',closestBoundry(x,y)+1,x,maximumBoundry) Line 34 in countSquares (Solution.py) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ret = Solution().countSquares(param_1) Line 65 in _driver (Solution.py) _driver() Line 80 in <module> (Solution.py)

@UniKylin
Copy link

Mr. Chen Hao has left us forever 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants