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