LeetCode 1436번
https://leetcode.com/problems/destination-city/

Set<String> set = new HashSet<>();
for(List<String> path : paths) {
set.add(path.get(0));
}
for(List<String> path : paths) {
String dest = path.get(1);
if(!set.contains(dest)) {
sb.append(dest);
return sb.toString();
}
}
set에 저장해서 출발지가 되는 중복하는 국가를 모두 제거한다.
다음은 목적지인 국가dest를 가져와서, set에 포함되어 있는지 아닌지를 파악하고 set에 없다면 갈 수 있는 최종목적지로 판단하고 정답을 출력하도록 했다.

import java.util.*;
class Solution {
public String destCity(List<List<String>> paths) {
StringBuilder sb = new StringBuilder();
Set<String> set = new HashSet<>();
for(List<String> path : paths) {
set.add(path.get(0));
}
for(List<String> path : paths) {
String dest = path.get(1);
if(!set.contains(dest)) {
sb.append(dest);
return sb.toString();
}
}
return sb.toString();
} // End of destCity()
} // End of Solution class