problem
solution
option 1 - backtracking
將拜訪過的位置,原地修改其陣列的值為 0
1 | class Solution { |
option 2 bfs
1 | class Solution { |
option 3 - *Union Find
analysis
- option 1
- time complexity
O(n*m)
- space complexity
O(n*m)
- time complexity
- option 2
- time complexity
O(n*m)
- space complexity
O(n*m)
- time complexity