class Solution {
public:
bool isPathCrossing(string path) {
set<pair<int, int>> s;
s.insert(make_pair(0,0));
int x=0, y=0;
for(auto p: path){
switch(p){
case 'N': x-=1; break;
case 'S': x+=1; break;
case 'W': y-=1; break;
case 'E': y+=1; break;
}
if(s.find(make_pair(x,y))!=s.end()) return true;
s.insert(make_pair(x,y));
}
return false;
}
};
- make_pair(x,y)可直接写为{x,y}