处理Python图形和字典问题时语法无效

2024-09-28 23:25:06 发布

您现在位置:Python中文网/ 问答频道 /正文

这就是我正在研究的问题:https://leetcode.com/problems/find-the-town-judge/

我的代码如下。我收到的语法错误无效

            truster[truster_key] = 0:

但是,错误消息没有详细说明,因此它所说的全部是无效语法。我不知道为什么它是无效的,我所做的只是添加到我的Python字典中

class Solution(object):
    def findJudge(self, N, trust):
        """
        :type N: int
        :type trust: List[List[int]]
        :rtype: int
        """
        if len(trust) == 0:
            return N

    count = 0

    trusted = {}
    truster = {}

    for i in range(len(trust)):
        trusted_key = trust[i][1]
        if trust[i][1] not in trusted:
            trusted[trusted_key] = 0
        else:
            trusted[trusted_key] = trusted[trusted_key] + 1

    for i in range(len(trust)):
        truster_key = truster[i][0]
        if trust[i][0] not in truster:
            truster[truster_key] = 0:
        else:
            truster[truster_key] == truster[truster_key] + 1

    for i in trusted:
        if i not in truster and trusted[i] >= N - 1:
            return i
    return -1

Tags: keyinforlenreturniftypenot