Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1021 Bytes

_1436. Destination City.md

File metadata and controls

46 lines (32 loc) · 1021 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 01, 2024

Last updated : July 01, 2024


Related Topics : Array, Hash Table, String

Acceptance Rate : 79.518 %


Solutions

Java

class Solution {
    public String destCity(List<List<String>> paths) {
        HashSet<String> srcs = new HashSet<>();

        for (int i = 0; i < paths.size(); i++) {
            srcs.add(paths.get(i).get(0));
        }

        for (int i = 0; i < paths.size(); i++) {
            if (!srcs.contains(paths.get(i).get(1))) {
                return paths.get(i).get(1);
            }
        }
        return null;
    }
}