Skip to content

Commit a55b8d1

Browse files
committed
Add solution #1436
1 parent 21bed45 commit a55b8d1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
1380|[Lucky Numbers in a Matrix](./1380-lucky-numbers-in-a-matrix.js)|Easy|
149149
1389|[Create Target Array in the Given Order](./1389-create-target-array-in-the-given-order.js)|Easy|
150150
1408|[String Matching in an Array](./1408-string-matching-in-an-array.js)|Easy|
151+
1436|[Destination City](./1436-destination-city.js)|Easy|
151152
1472|[Design Browser History](./1472-design-browser-history.js)|Medium|
152153
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
153154
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|

solutions/1436-destination-city.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 1436. Destination City
3+
* https://leetcode.com/problems/destination-city/
4+
* Difficulty: Easy
5+
*
6+
* You are given the array paths, where paths[i] = [cityAi, cityBi] means there
7+
* exists a direct path going from cityAi to cityBi. Return the destination city,
8+
* that is, the city without any path outgoing to another city.
9+
*
10+
* It is guaranteed that the graph of paths forms a line without any loop, therefore,
11+
* there will be exactly one destination city.
12+
*/
13+
14+
/**
15+
* @param {string[][]} paths
16+
* @return {string}
17+
*/
18+
var destCity = function(paths) {
19+
const set = new Set(paths.map(([a]) => a));
20+
return paths.find(([_, b]) => !set.has(b))[1];
21+
};

0 commit comments

Comments
 (0)