Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public function spiralOrder(matrix:Array):Array
- {
- var arr:Array = [];
- var stopLevel:int = Math.ceil(matrix.length / 2);
- for (var level:int = 0; level < stopLevel; level++)
- {
- var start:int = level;
- var end:int = matrix[0].length - level;
- var endLevel:int = matrix.length - level;
- // top
- for (var i:int = start; i < end; i++)
- {
- arr.push({h: level, v: i});
- }
- // right
- for (var j:int = level + 1; j < endLevel; j++)
- {
- arr.push({h: j, v: end - 1});
- }
- // bottom
- for (var k:int = end - 2; k > start; k--)
- {
- arr.push({h: endLevel - 1, v: k});
- }
- // left
- for (var l:int = endLevel - 1; l > level; l--)
- {
- arr.push({h: l, v: start});
- }
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement