原题链接:https://leetcode-cn.com/problems/spiral-matrix-ii/

相关题目:螺旋矩阵

vector<vector<int>> generateMatrix(int n) {vector<vector<int>> ans(n,vector<int>(n,0));int u=0;int d=n-1;int l=0;int r=n-1;int count=1;while(count<=n*n){for(int i=l;i<=r;i++) ans[u][i]=count++;//从左到右u++;for(int i=u;i<=d;i++) ans[i][r]=count++;//从上到下r--;for(int i=r;i>=l;i--) ans[d][i]=count++;//从右到左d--;for(int i=d;i>=u;i--) ans[i][l]=count++;//从下到上l++;}return ans;
}

leetcode算法题--螺旋矩阵 II相关推荐

  1. leetcode算法题--螺旋矩阵

    原文链接:https://leetcode-cn.com/problems/spiral-matrix/ vector<int> spiralOrder(vector<vector& ...

  2. LeetCode实战:螺旋矩阵 II

    题目英文 Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 in spir ...

  3. LeetCode算法题-Valid Palindrome II(Java实现)

    这是悦乐书的第287次更新,第304篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第155题(顺位题号是680).给定非空字符串s,最多可以删除一个字符. 判断它是否是回 ...

  4. leetcode算法题--Unique Paths II

    原题链接:https://leetcode.com/problems/unique-paths-ii/ class Solution {public:int uniquePathsWithObstac ...

  5. leetcode算法题--Jump Game II

    原题链接:https://leetcode.com/problems/jump-game-ii/ int jump(vector<int>& nums) {int l = 0, r ...

  6. leetcode系列-59. 螺旋矩阵 II

    题目描述:给你一个正整数 n ,生成一个包含 1 到 n2 所有元素, 且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix . 示例 1: 输入:n = 3 输出:[[1,2,3],[ ...

  7. leetcode算法题--剪绳子 II

    原题链接:https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/ 相关题目:剪绳子 1.循环求余法 //(x ^ a) % p; long re ...

  8. leetcode算法题--环形链表 II★

    原题链接:https://leetcode-cn.com/problems/linked-list-cycle-ii/ 1.map ListNode *detectCycle(ListNode *he ...

  9. leetcode算法题--反转链表 II★

    原题链接:https://leetcode-cn.com/problems/reverse-linked-list-ii/ 1.头插法 ListNode* reverseBetween(ListNod ...

最新文章

  1. 技术05期:五分钟教你读懂卷积神经网络【CNN】
  2. JDK、J2EE、J2SE、J2ME的区别
  3. 深度学习时代的数据科学和自然语言处理
  4. 如何在Linux(ubuntu21.04)下安装chrome浏览器
  5. mysql fetch rows,php中mysql_fetch_array()和mysql_fetch_rows()函数区别
  6. webstorm 设置tslint_webstorm(2019)配置eslint规范
  7. 计算机网络实验11.6.1,6.111 2004春季课程:数位系统概论实验(Introductory Digital Systems Laboratory, Spring 2004)...
  8. 【递归】桐桐的递归函数
  9. Linux 查看系统硬件信息
  10. WIN7开启WIFI
  11. SeleniumCSS选择器
  12. WorldWind学习系列六:渲染过程解析篇
  13. Linux下多线程调试以及查看信息
  14. mysql查询表字段的个数
  15. LeetCode 1818、绝对差值和
  16. 常用的C语言编程工具
  17. VS2017下解决:error LNK2019: 无法解析的外部符号 __iob_func
  18. 性能测试指标及常用监控工具
  19. centos基本命令
  20. python-简单用户登录注册界面实现

热门文章

  1. python小程序-【Python精华】100个Python练手小程序
  2. python代码大全o-Python O
  3. python turtle画椭圆-【python turtle如何画椭圆】
  4. python装饰器类-基于类的python装饰器
  5. python小程序源代码-10个Python练手小程序
  6. python调用shell命令-python调用shell命令小结
  7. python爬虫下载-用Python爬虫下载整本小说
  8. python3官方最新下载-python3.7
  9. Linux查看和剔除当前登录用户详细教程
  10. mysql的学习总结