JavaScript solution: straightforward with graph
The key point is to traverse the elements in correct order.\n### Steps:\n Find out how many times we should do the traversal (four lines one time, as shown in t
The key point is to traverse the elements in correct order.\n### Steps:\n* Find out how many times we should do the traversal (four lines one time, as shown in the graph);\n* Each time, we traverse four lines, and we push every element we meet, no matter whether they belong to the matrix or not;\n* We filter the result we got, and leave only elements that belong to the matrix.\n![image](https://s3-lc-upload.s3.amazonaws.com/users/lmiaoj/image_1534089926.png)\n\n```\nvar spiralMatrixIII = function(R, C, r0, c0) {\n    let n = Math.max(r0, c0, R-1-r0, C-1-c0);\n    let res = [[r0,c0]];\n    for(let i=1; i<=n; i++){\n    \tfor(let j=1-i; j<=i; j++) res.push([r0+j,c0+i]); //line 1\n    \tfor(let j=i-1; j>=-i; j--) res.push([r0+i,c0+j]); //line 2\n    \tfor(let j=i-1; j>=-i; j--) res.push([r0+j,c0-i]); //line 3\n    \tfor(let j=1-i; j<=i; j++) res.push([r0-i,c0+j]); //line 4\n    }\n    return res.filter(x=>x[0]>=0&&x[0]<R&&x[1]>=0&&x[1]<C);\n};\n```
[]