https://leetcode.com/problems/destination-city/
| 6 | * https://leetcode.com/problems/destination-city/ |
| 7 | */ |
| 8 | public class Sanghoo { |
| 9 | |
| 10 | // 목적지는 어떠한 경로의 첫 번째 도시가 될 수 없음을 이용 |
| 11 | public String destCity(List<List<String>> paths) { |
| 12 | String res = ""; |
| 13 | StringBuilder firstCitys = new StringBuilder(); |
| 14 | |
| 15 | // 첫 번째 도시 세팅 |
| 16 | for(List<String> path : paths) { |
| 17 | String firstCity = path.get(0); |
| 18 | firstCitys = firstCitys.append(firstCity); |
| 19 | } |
| 20 | |
| 21 | // 두 번째 도시들 중 첫 번째 도시에 해당하지 않는 도시 찾기 |
| 22 | for(List<String> path : paths) { |
| 23 | String lastCity = path.get(1); |
| 24 | |
| 25 | if(firstCitys.indexOf(lastCity) < 0) { |
| 26 | res = lastCity; |
| 27 | break; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return res; |
| 32 | } |
| 33 | |
| 34 | } |
nothing calls this directly
no outgoing calls
no test coverage detected