Skip to content

Commit ae8e93e

Browse files
authored
Create destination-city.cpp
1 parent 8667167 commit ae8e93e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

C++/destination-city.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
string destCity(vector<vector<string>>& paths) {
7+
unordered_set<string> A, B;
8+
for (const auto& path : paths) {
9+
A.emplace(path[0]);
10+
B.emplace(path[1]);
11+
}
12+
for (const auto& dst : B) {
13+
if (!A.count(dst)) {
14+
return dst;
15+
}
16+
}
17+
return "";
18+
}
19+
};

0 commit comments

Comments
 (0)