Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1018 Bytes

_1436. Destination City.md

File metadata and controls

44 lines (32 loc) · 1018 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.48 %


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;
    }
}