package leetcode;

/**
 * https://leetcode.com/problems/path-crossing/
 */
public class Problem1496 {
    public boolean isPathCrossing(String path) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1496 prob = new Problem1496();
        System.out.println(prob.isPathCrossing("NES")); // false
        System.out.println(prob.isPathCrossing("NESWW")); // true
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -205,266 +205,583 @@
     
-// TODO%0A        return false
+Set%3CString%3E set = new HashSet%3C%3E();%0A        int row = 0
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1496 prob = new Problem1496();%0A        System.out.println(prob.isPathCrossing(%22NES%22)); // false%0A        System.out.println(prob.isPathCrossing(%22NESWW%22)); // true
+int col = 0;%0A        set.add(row + %22,%22 + col);%0A        for (char c : path.toCharArray()) %7B%0A            if (c == 'N') %7B%0A                row--;%0A            %7D else if (c == 'E') %7B%0A                col++;%0A            %7D else if (c == 'S') %7B%0A                row++;%0A            %7D else %7B // if (c == 'W)%0A                col--;%0A            %7D%0A            String key = row + %22,%22 + col;%0A            if (set.contains(key)) %7B%0A                return true;%0A            %7D%0A            set.add(key);%0A        %7D%0A        return false;
 %0A   

Solve problem 1496