Skip to content

Commit 28df400

Browse files
committed
Runtime 7 ms (Top 98.28%) | Memory 10.0 MB (Top 79.46%)
1 parent 7aa0841 commit 28df400

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
class Solution {
22
public:
33
string destCity(vector<vector<string>>& paths) {
4-
string ans="";
5-
int flag=0;
6-
for(int i=0;i<paths.size();i++){
7-
for(int j=0;j<paths.size();j++){
8-
if(paths[i][1]==paths[j][0])
9-
break;
10-
else{
11-
12-
if(j==paths.size()-1){
13-
ans+=paths[i][1];
14-
flag=1;
15-
break;
16-
}
17-
}
18-
}
19-
if(flag==1)
20-
break;
4+
string ans;
5+
unordered_map<string, int> m;
6+
for(int i=0; i<paths.size(); i++){
7+
m[paths[i][0]]++;
8+
m[paths[i][1]]--;
219
}
10+
for(auto city : m){
11+
if(city.second == -1) ans = city.first;
12+
}
13+
2214
return ans;
2315
}
24-
};
16+
};

0 commit comments

Comments
 (0)