Skip to content

Instantly share code, notes, and snippets.

View santoshtechwiz's full-sized avatar

santosh kumar singh santoshtechwiz

View GitHub Profile
@santoshtechwiz
santoshtechwiz / LeetCode-Spiral Matrix II
Created February 12, 2017 09:23 — forked from luoxiaoxun/LeetCode-Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]
C++:
class Solution {
public:
vector<vector<int> > generateMatrix(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n<=0) return vector<vector<int>>();
vector<vector<int>> result(n,vector<int>(n));
int xBeg=0,xEnd=n-1;
int yBeg=0,yEnd=n-1;