package leetcode;

/**
 * https://leetcode.com/problems/open-the-lock/description/
 */
public class Problem753 {
    public int openLock(String[] deadends, String target) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem753 prob = new Problem753();
        System.out.println(prob.openLock(new String[]{"0201", "0101", "0102", "1212", "2002"}, "0202")); // 6
        System.out.println(prob.openLock(new String[]{"8888"}, "0009")); // 1
        System.out.println(prob.openLock(new String[]{"8887", "8889", "8878", "8898", "8788", "8988", "7888", "9888"}, "8888")); // -1
        System.out.println(prob.openLock(new String[]{"0000"}, "8888")); // -1
    }
}

@@ -12,16 +12,169 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Queue;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -331,32 +331,1158 @@
     
-// TODO%0A        return 0
+Set%3CString%3E deads = new HashSet%3C%3E();%0A        for (String dead : deadends) %7B%0A            deads.add(dead);%0A        %7D%0A        int result = -1;%0A        Set%3CString%3E visited = new HashSet%3C%3E();%0A        Queue%3CString%3E queue = new LinkedList%3C%3E();%0A        queue.add(%220000%22);%0A        while (!queue.isEmpty()) %7B%0A            String current = queue.remove();%0A            if (deads.contains(current)) %7B%0A                continue;%0A            %7D%0A            for (String neighbor : getNeighbors(current)) %7B%0A                if (!visited.contains(neighbor)) %7B%0A                    queue.add(neighbor);%0A                    visited.add(neighbor);%0A                %7D%0A            %7D%0A        %7D%0A        return -1;%0A    %7D%0A%0A    private static List%3CString%3E getNeighbors(String node) %7B%0A        List%3CString%3E neighbors = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C node.length(); i++) %7B%0A            int n1 = (node.charAt(i) - '0' - 1) %25 10;%0A            neighbors.add(node.substring(0, i) + n1 + node.substring(i + 1));%0A            int n2 = (node.charAt(i) - '0' + 1) %25 10;%0A            neighbors.add(node.substring(0, i) + n2 + node.substring(i + 1));%0A        %7D%0A        return neighbors
 ;%0A  
@@ -1894,24 +1894,24 @@
 8%22)); // -1%0A
-
         Syst
@@ -1973,20 +1973,102 @@
 8%22)); // -1%0A
+//        System.out.println(%221234%22.substring(0, 1) + '0' + %221234%22.substring(2));%0A
     %7D%0A%7D%0A

Update problem 753