997. 找到小镇的法官

在这里插入图片描述

class Solution(object):
    def findJudge(self, N, trust):
        """
        :type N: int
        :type trust: List[List[int]]
        :rtype: int
        """
        res = [0] * N
        res_1 = [0] * N
        for item in trust:
            res[item[1] - 1] += 1
            res_1[item[0] - 1] += 1
        for i in range(1, N+1):
            if res[i-1] == N - 1 and res_1[i-1] == 0:
                    return i
        return -1

猜你喜欢

转载自blog.csdn.net/zyy848877920/article/details/88909862