广州地铁老外比中指说中国女人鸡,引乘客蜂拥围殴 (转载)# Joke - 肚皮舞运动
l*2
1 楼
2D matrix with 0s and 1s. Try to find out how many countries in this matrix?
For example:
[[1,1,1,0]
[1,1,0,0]
[0,0,0,1]]
return 3, because one for 1s, one for 0s, and one for the last one.
another example:
[[1,1,1,1]
[0,0,0,0]
[1,0,0,1]]
return 4
LZ想到的是用DFS 和 boolean[][] visited, 大家还有什么好方法吗?
另外,看到一道面经提示用 unit and find,不知道是不是可以帮忙看看怎么写?不是
很熟
count islands in a m*n grid (一个联通的值为1的区域被视为一个island)
例:
0011010
0010010
1000110
0000001
4 islands found in above grid
For example:
[[1,1,1,0]
[1,1,0,0]
[0,0,0,1]]
return 3, because one for 1s, one for 0s, and one for the last one.
another example:
[[1,1,1,1]
[0,0,0,0]
[1,0,0,1]]
return 4
LZ想到的是用DFS 和 boolean[][] visited, 大家还有什么好方法吗?
另外,看到一道面经提示用 unit and find,不知道是不是可以帮忙看看怎么写?不是
很熟
count islands in a m*n grid (一个联通的值为1的区域被视为一个island)
例:
0011010
0010010
1000110
0000001
4 islands found in above grid