File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 148
148
1380|[ Lucky Numbers in a Matrix] ( ./1380-lucky-numbers-in-a-matrix.js ) |Easy|
149
149
1389|[ Create Target Array in the Given Order] ( ./1389-create-target-array-in-the-given-order.js ) |Easy|
150
150
1408|[ String Matching in an Array] ( ./1408-string-matching-in-an-array.js ) |Easy|
151
+ 1436|[ Destination City] ( ./1436-destination-city.js ) |Easy|
151
152
1472|[ Design Browser History] ( ./1472-design-browser-history.js ) |Medium|
152
153
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
153
154
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments