【leetcode】找到小镇的法官

 

int findJudge(int N, int** trust, int trustSize, int* trustColSize){
    int total=(N+1)*N/2,i;
    int hash[1001]={0};
    for (i=0; i<trustSize; i++)
    {
        hash[trust[i][0]]=-1;
        if (hash[trust[i][1]]>=0)
            hash[trust[i][1]]+=trust[i][0];        
    }
    for (i=1; i<=N; i++)
        if (hash[i] != -1 && hash[i]+i == total) return i;

    return -1;
}

 

posted @ 2020-09-28 14:32  温暖了寂寞  阅读(113)  评论(0编辑  收藏  举报