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;
    }
}
相关推荐
Heris9915 分钟前
2.22 c++练习【operator运算符重载、封装消息队列、封装信号灯集】
开发语言·c++
----云烟----17 分钟前
C/C++ 中 volatile 关键字详解
c语言·开发语言·c++
mjr25 分钟前
设计模式-Java
java·设计模式
零星_AagT28 分钟前
Apache-CC6链审计笔记
java·笔记·apache·代码审计
01_29 分钟前
力扣hot100 ——搜索二维矩阵 || m+n复杂度优化解法
算法·leetcode·矩阵
SylviaW0832 分钟前
python-leetcode 35.二叉树的中序遍历
算法·leetcode·职场和发展
篮l球场33 分钟前
LeetCodehot 力扣热题100
算法·leetcode·职场和发展
yuanpan36 分钟前
23种设计模式之《组合模式(Composite)》在c#中的应用及理解
开发语言·设计模式·c#·组合模式
程序员张339 分钟前
使用IDEA提交SpringBoot项目到Gitee上
java·gitee·intellij-idea
BanLul1 小时前
进程与线程 (三)——线程间通信
c语言·开发语言·算法