leetcode-547. 朋友圈-C语言

/* 
 * 算法思想: 并查集
 * 
 */

int find(int *arr, int i){
    return i==arr[i] ? i : (arr[i] = find(arr, arr[i]));
}

void un(int *arr, int i, int j){
    int x = find(arr, i);
    int y = find(arr, j);
    
    arr[y] = x;
}

int cmp(int *a, int *b){
    return *a - *b;
}

int findCircleNum(int** M, int m, int* ns){
    int i, j, len = m + 1, n = ns[0], last=INT_MAX, cnt=0;
    if(!m || !m) return 0;
    
    int arr[len];
    
    for(i=1; i

你可能感兴趣的:(LeetCode)