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

首頁 > 學院 > 開發(fā)設計 > 正文

59. Spiral Matrix II

2019-11-06 06:10:24
字體:
來源:轉載
供稿:網友

挺簡單的,不過要考慮邊緣情況。注意細節(jié)

class Solution {public: vector<vector<int>> generateMatrix(int n) { vector<int> temp(n,0); vector<vector<int>> result; for(int i=0;i<n;i++) result.push_back(temp); int step=n; int direction=0; int startNum=1; int startFirst=0; int startSecond=-1; while(step!=0) { if(direction==0) { startSecond+=1; int temp=step; while(temp--) result[startFirst][startSecond++]=startNum++; startSecond--; direction=1; step--; } else if(direction==1) { startFirst+=1; int temp=step; while(temp--) result[startFirst++][startSecond]=startNum++; startFirst--; direction=2; } else if(direction==2) { startSecond-=1; int temp=step; while(temp--) result[startFirst][startSecond--]=startNum++; startSecond++; direction=3; step--; } else { startFirst-=1; int temp=step; while(temp--) result[startFirst--][startSecond]=startNum++; startFirst++; direction=0; } } return result; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 高清| 鲜城| 丰台区| 陵川县| 泰安市| 镇康县| 横山县| 赞皇县| 黄石市| 东丰县| 平塘县| 新源县| 和顺县| 固原市| 黄冈市| 建始县| 竹山县| 涞水县| 鹿泉市| 达孜县| 南康市| 怀仁县| 渝中区| 河池市| 遵化市| 武安市| 谷城县| 唐海县| 新巴尔虎右旗| 津市市| 遵义县| 贵德县| 赞皇县| 拉孜县| 淮滨县| 铁岭县| 襄城县| 太谷县| 梨树县| 台中县| 霍城县|