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

首頁 > 學院 > 開發設計 > 正文

Spiral Matrix

2019-11-14 09:45:50
字體:
來源:轉載
供稿:網友

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

For example,Given the following matrix:

[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]

You should return [1,2,3,6,9,8,7,4,5].

vector<int> fun(vector<vector<int> > &matrix){	vector<int> result;	int m = matrix.size();	int n = matrix[0].size();	int left = 0;	int right = n-1;	int top = 0;	int bottom = m-1;	while (left <= right && top <= bottom)	{		if (top <= bottom)		{			for (int i = left; i <= right; i++)			{				result.push_back(matrix[top][i]);			}			top++;		}				if (left <= right)		{			for (int i = top; i <= bottom; i++)			{				result.push_back(matrix[i][right]);			}			right--;		}		if (top <= bottom)		{			for (int i = right; i >= left; i--)			{				result.push_back(matrix[bottom][i]);			}			bottom--;		}		if (left <= right)		{			for (int i = bottom; i >= top; i--)			{				result.push_back(matrix[i][left]);			}			left++;		}	}	return result;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牙克石市| 克拉玛依市| 普安县| 聂拉木县| 曲松县| 铅山县| 闽侯县| 革吉县| 徐汇区| 湘阴县| 文山县| 宜兰市| 伊宁市| 潜江市| 嵊州市| 宁河县| 始兴县| 鹰潭市| 洛扎县| 深水埗区| 茶陵县| 客服| 桓台县| 清水县| 鄂托克前旗| 威宁| 尼勒克县| 莆田市| 磐石市| 个旧市| 海宁市| 阜康市| 滕州市| 太谷县| 罗江县| 洞头县| 南丹县| 宁蒗| 武胜县| 房产| 玛多县|