typedef pair<int, int> step_type;
class Solution {
public:
bool isPathCrossing(string path) {
int x = 0;
int y = 0;
vector<step_type> step;
step_type default_step(0, 0);
step.push_back(default_step);
for(int n = 0; n < path.size(); n++) {
if (path[n] == 'N') {
y = y + 1;
} else if (path[n] == 'S') {
y = y - 1;
} else if (path[n] == 'E') {
x = x + 1;
}else if (path[n] == 'W') {
x = x - 1;
}
step_type simple_step(x, y);
vector<step_type>::iterator result = find(step.begin( ), step.end( ), simple_step); //查找3
if (result == step.end()){
step.push_back(simple_step);
} else {
return true;
}
}
return false;
}
};