How to express the grid in python


  • 0
    S

    In this question, the problem gives a 2d grid map of '1's (land) and '0's (water). But I have no idea how to express it in python. Can anyone help me? thanks.


  • 0
    L

    Since one cannot do something like:

    str = '12345'
    str[2]='a'
    

    What I do is convert the grid from List[List[str]] to List[List[int]].
    This make it slow, but I'm not sure how to make it fast. Anyone?


  • 0
    G

    @lei31
    I converted it to list[list[char]]. It seems not slow.:

    matrix = [list(x) for x in grid]
    

Log in to reply
 

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