Problem LeetCode 200. Number of Islands LeetCode : 737. Sentence Similarity II
[Union-Find][String][Hash Table][Depth-First Search] LeetCode 200. Number of Islands 這一題用 BFS 或是 DFS 可以很簡單的解出來,這邊試著用這題練習簡易的 Union Find。 一開始,只要遇到 1 就將 counter 加上 1 。之後只要 union 成功,counter 就 減 1 ,最後 counter 就是 island 個數。 class Solution {
private:
int X[4] = {0, 0, 1…