国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Spiral Matrix II

2019-11-14 09:04:58
字體:
供稿:網(wǎng)友

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 ]]

vector<vector<int> > fun(int n){	vector<vector<int> > result(n, vector<int>(n));	int left = 0;	int right = n-1;	int top = 0;	int bottom = n-1;	int count = 0;	int total = n*n;	while (count < total)	{		for (int i = left; i <= right && count < total; i++)		{			count++;			result[top][i] = count;		}		top++;		for (int i = top; i <= bottom && count < total; i++)		{			count++;			result[i][right] = count;		}		right--;		for (int i = right; i >= left && count < total; i--)		{			count++;			result[bottom][i] = count;		}		bottom--;		for (int i = bottom; i >= top && count < total; i--)		{			count++;			result[i][left] = count;		}		left++;	}	return result;}


上一篇:XMLTag詳解

下一篇:webrtc,人臉拍照小功能

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 昌吉市| 蓬溪县| 岳西县| 澜沧| 井研县| 青田县| 古浪县| 天长市| 新民市| 石家庄市| 弋阳县| 大连市| 颍上县| 安义县| 昆山市| 麟游县| 来宾市| 静海县| 烟台市| 北京市| 洞口县| 浦东新区| 芦溪县| 南召县| 阿克陶县| 老河口市| 涞源县| 陕西省| 改则县| 榆林市| 渭源县| 普安县| 德庆县| 湖南省| 遵化市| 枣阳市| 台湾省| 榕江县| 兴安县| 云龙县| 通榆县|