Brute Force Python


  • 1

    Update

    Simpler version inspired by yibin_easy's solution.

    def minArea(self, image, x, y):
        a, b = (sum('1' in row for row in image)
                for image in (image, zip(*image)))
        return a * b
    

    Or:

    def minArea(self, image, x, y):
        return sum('1' in r for r in image) * sum('1' in r for r in zip(*image))
    

    Old

    def minArea(self, image, x, y):
        a, b = (max(I) - min(I) + 1
                for image in (image, zip(*image))
                for I in [[i for i, row in enumerate(image) if '1' in row]])
        return a * b
    

    Gets accepted in about 108 ms...


  • 0
    D

    Worst python code ever! there is no readability at all about this code. Python philosophy entourages simple straightforward and clear. Yall'd better write scala code instead of python. Their community encourage mysterious and enigmatic code piece like this.


  • 0
    C

    If you can kill a bull with a chopstick, I'd say it's an admirable use of the chopstick, without diminishing the value of using the same chopsticks for sushi consumption. I don't think chopsticks would be offended by such deeds.


  • 0
    L

    said in Brute Force Python:

    def minArea(self, image, x, y):
    return sum('1' in r for r in image) * sum('1' in r for r in zip(*image))

    could you explain the runtime of the second sum, particularly zip(*image)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.