Java LeetCode每日一题

997. 找到小镇的法官

java 复制代码
package JavaExercise20241002;

public class JavaExercise {
    public static void main(String[] args) {
        int[][] array = {{1,3},{2,3},{3,1}};
        Solution solution = new Solution();
        System.out.println(solution.findJudge(3, array));
    }
}

class Solution {
    public int findJudge(int n, int[][] trust) {
        int[] out = new int[n + 1];
        int[] in = new int[n + 1];

        for (int[] edges : trust) {
            int x = edges[0];
            int y = edges[1];
            out[x]++;
            in[y]++;
        }

        for (int i = 1; i <= n; i++) {
            if (out[i] == 0 && in[i] == (n - 1)) {
                return i;
            }
        }
        return -1;
    }
}
相关推荐
dapeng287026 分钟前
分布式系统容错设计
开发语言·c++·算法
qq_4176950531 分钟前
代码热修复技术
开发语言·c++·算法
badhope5 小时前
Mobile-Skills:移动端技能可视化的创新实践
开发语言·人工智能·git·智能手机·github
码云数智-园园6 小时前
微服务架构下的分布式事务:在一致性与可用性之间寻找平衡
开发语言
C++ 老炮儿的技术栈7 小时前
volatile使用场景
linux·服务器·c语言·开发语言·c++
hz_zhangrl7 小时前
CCF-GESP 等级考试 2026年3月认证C++一级真题解析
开发语言·c++·gesp·gesp2026年3月·gespc++一级
大阿明7 小时前
Spring Boot(快速上手)
java·spring boot·后端
Liu628887 小时前
C++中的工厂模式高级应用
开发语言·c++·算法
bearpping7 小时前
Java进阶,时间与日期,包装类,正则表达式
java
IT猿手7 小时前
基于控制障碍函数的多无人机编队动态避障控制方法研究,MATLAB代码
开发语言·matlab·无人机·openclaw·多无人机动态避障路径规划·无人机编队