MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/String/1436. Destination City/Sanghoo.java:8–34  ·  view source on GitHub ↗

https://leetcode.com/problems/destination-city/

Source from the content-addressed store, hash-verified

6 * https://leetcode.com/problems/destination-city/
7 */
8public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected