Destination City
给一个list, 里面的字符串是两个城市之间的路, 求一个城市, 没有出口.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class Solution { public String destCity(List<List<String>> paths) { Set<String> set = new HashSet<>(); for(List<String> l : paths) { set.add(l.get(0)); set.add(l.get(1)); } for(List<String> l : paths) { if(set.contains(l.get(0))) { set.remove(l.get(0)); } } return set.iterator().next(); } } |