Skip to content

Commit c8a33d0

Browse files
add 1436
1 parent b31ce4b commit c8a33d0

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1436|[Destination City](https://leetcode.com/problems/destination-city/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1436.java) | |Easy|String|
1112
|1432|[Max Difference You Can Get From Changing an Integer](https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1432.java) | |Medium|String|
1213
|1431|[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1431.java) | |Easy|Array|
1314
|1423|[Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1423.java) | |Medium|Array, DP, Sliding Window|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Set;
6+
7+
public class _1436 {
8+
public static class Solution1 {
9+
public String destCity(List<List<String>> paths) {
10+
Set<String> sourceSet = new HashSet<>();
11+
Set<String> destSet = new HashSet<>();
12+
for (List<String> path : paths) {
13+
String source = path.get(0);
14+
String dest = path.get(1);
15+
sourceSet.add(source);
16+
destSet.add(dest);
17+
}
18+
for (String dest : destSet) {
19+
if (!sourceSet.contains(dest)) {
20+
return dest;
21+
}
22+
}
23+
return "";
24+
}
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1436;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
import static junit.framework.TestCase.assertEquals;
11+
12+
public class _1436Test {
13+
private static _1436.Solution1 solution1;
14+
private static List<List<String>> paths;
15+
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _1436.Solution1();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
paths = Arrays.asList(Arrays.asList("Lima", "Sao Paulo"), Arrays.asList("New York", "Lima"), Arrays.asList("London", "New York"));
24+
assertEquals("Sao Paulo", solution1.destCity(paths));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)