
g1401_1500.s1436_destination_city.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java17 Show documentation
Show all versions of leetcode-in-java17 Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
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