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;
    }
}
相关推荐
平常心的技术小牛14 小时前
Qt-快速上手-QMenuBar
开发语言·qt
青 春 记 忆15 小时前
零基础入门Python11|Git实战:为任务管理器建立版本历史
开发语言·git·vscode·python·python3.11
To_OC15 小时前
LC 239 滑动窗口最大值:从暴力超时到单调队列一遍过
javascript·算法·leetcode
2601_9638702015 小时前
【计算机毕业设计】基于Spring Boot的专科医院医疗管理系统
java·spring boot·课程设计
Bingo_BIG15 小时前
Java Spring 批量修改,实体、接口、方法的定义
java·spring
.道阻且长.16 小时前
9.LeetCode算法习题讲解--滑动窗口--无重复字符的最长字串
算法·leetcode·职场和发展·哈希算法
画中有画16 小时前
软件架构中质量属性(性能、安全、可扩展性)的权衡设计
java·运维·安全
Shaoxi Zhang16 小时前
JAVA学习笔记035——对象和JSON格式
java·笔记·学习
赵丙双16 小时前
CountDownLatch 源码分析
java·aqs·countdownlatch
余额瞒着我当琳16 小时前
C++--深拷贝三件套 + swap + 写时拷贝 + vector 扩容 + reserve
java·开发语言·c++