1
假設您有形式的數組:在二維數組查找連續的塊
[
[2, 2, 3, 4],
[2, 3, 5, 5],
[2, 2, 2, 5],
[3, 2, 2, 4],
]
,並希望找到數字連續的塊的座標,在這種情況下:
[
# the 2s:
[(0,0), (0,1), (1,0), (2,0), (2,1), (2,2), (3,1), (3,2)],
# and the 5s:
[(1,2), (1,3), (2,3)]
]
你會如何做它?