Excellent video. Thank you Nick for making these videos. Below is an alternative solution I developed. It uses a single "level" tracker, rather than the row start + end and column start + end trackers. Each level is one "spiral" around the outside edge of the currently active region. public int[][] generateMatrix(int n) { int[][] matrix = new int[n][n]; int level = 0; int currentNumber = 1; while (level = level; i--) { int rowIndex = n - level - 1; matrix[rowIndex][i] = currentNumber++; } // fill in left side column for (int i = n - level - 2; i > level ; i--) { /* the "> level" bound takes care of not overlapping with the top row that's already been filled in for tis level */ matrix[i][level] = currentNumber++; } level++; } return matrix; }
@indiansoftwareengineer48994 жыл бұрын
thanks Brad.
@user-pr6lv7nd6l3 жыл бұрын
I did the same way
@Demonic79221 Жыл бұрын
Thanks for the simple and clear explanation! This solution is easy understanding than LeetCode Editorials.
@satyamgupta6030 Жыл бұрын
thanks alot nick already saw the last video just saw this video if I could learn something new and guess what I did thanks.
@millionaires12 жыл бұрын
Nice explanation
@hhjdkdnchidnd2 жыл бұрын
Hi Nick can you make a video for Spiral Matrix III (885)? I am still confused it. Thank you
@deepeshgurnani16712 жыл бұрын
Hi, Great video Can you make a video for spiral matrix 3 885 leetcode medium ?