java solution just like clean robot~
Just like robot clean problem, usecurDirectionto record the curDirection and (curDirection + 1) % 4to find the next direction.\nWhen the direction is equals 0 o
Just like robot clean problem, use```curDirection```to record the curDirection and ```(curDirection + 1) % 4```to find the next direction.\nWhen the direction is equals 0 or 2, ```len++```\u3002\n```\nclass Solution {\n    public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {\n        int[] dx = new int[]{0, 1, 0, -1};\n        int[] dy = new int[]{1, 0, -1, 0};\n        List<int[]> list = new ArrayList<>();\n        int curDirection = 0;\n        list.add(new int[]{r0, c0});\n        int len = 0;\n        while (list.size() < R * C) {\n            if (curDirection == 0 || curDirection == 2) len++;\n            for (int i = 0; i < len; i++) {\n                r0 += dx[curDirection];\n                c0 += dy[curDirection];\n                if (r0 < 0 || r0 >= R || c0 < 0 || c0 >= C) continue;\n                list.add(new int[]{r0, c0});\n            }\n            curDirection = (curDirection + 1) % 4;\n        }\n        int[][] res = new int[list.size()][2];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = list.get(i);\n        }\n        return res;\n    }\n}\n```
[]