Spiral Matrix II

Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order.

Solution:

Similar to Spiral Matrix. Actually it is easier since we always generate square matrix, so the number of bound conditions are much less.

Not sure how to directly use vectors. Here we use 2d array as first step.

The following code passes LeetCode Online Large Judge.

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs