1
// Path crossing
2
// Leetcode
3

4
class Solution {
5
public boolean isPathCrossing(String path) {
6
Set<String> visited = new HashSet<>();
7
int x = 0, y = 0;
8
visited.add(x + "," + y);
9
for (char c : path.toCharArray()) {
10
if (c == 'N') y++;
11
else if (c == 'S') y--;
12
else if (c == 'E') x++;
13
else x--;
14
if (visited.contains(x + "," + y)) return true;
15
visited.add(x + "," + y);
16
}
17
return false;
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0