All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1401_1500.s1436_destination_city.Solution Maven / Gradle / Ivy

There is a newer version: 1.24
Show newest version
package g1401_1500.s1436_destination_city;

// #Easy #String #Hash_Table #2022_03_28_Time_7_ms_(11.79%)_Space_44.2_MB_(27.60%)

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public String destCity(List> paths) {
        Set sourceSet = new HashSet<>();
        Set destSet = new HashSet<>();
        for (List path : paths) {
            String source = path.get(0);
            String dest = path.get(1);
            sourceSet.add(source);
            destSet.add(dest);
        }
        for (String dest : destSet) {
            if (!sourceSet.contains(dest)) {
                return dest;
            }
        }
        return "";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy