当前位置: 首页 > news >正文

网页设计网站制作收获推广文章

网页设计网站制作收获,推广文章,闸北区网站建设网页制作,网站建设的原则 流程给定一个正整数 n#xff0c;生成一个包含 1 到 n^2 所有元素#xff0c;且元素按顺时针顺序螺旋排列的正方形矩阵。 示例: 输入: 3 输出: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] 解#xff1a; class Solution {public int[][] generateMatrix(int n) {int[][] ar…给定一个正整数 n生成一个包含 1 到 n^2 所有元素且元素按顺时针顺序螺旋排列的正方形矩阵。 示例: 输入: 3 输出: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] 解 class Solution {public int[][] generateMatrix(int n) {int[][] arr new int[n][n]; // 创建 n * n 数组 ​int topRow 0, bottomRow n - 1; // 定义上边界和下边界int leftCol 0, rightCol n - 1; // 定义左边界和右边界int direction 0; // 初始方向0代表向右 ​int num 1; // 要赋的值 ​while (topRow bottomRow leftCol rightCol) {if (direction 0) { // 向右for (int i leftCol; i rightCol; i) {arr[topRow][i] num;}topRow; // 上边界下移} else if (direction 1) { // 向下for (int i topRow; i bottomRow; i) {arr[i][rightCol] num;}rightCol--; // 右边界左移} else if (direction 2) { // 向左for (int i rightCol; i leftCol; i--) {arr[bottomRow][i] num;}bottomRow--; // 下边界上移} else if (direction 3) { // 向上for (int i bottomRow; i topRow; i--) {arr[i][leftCol] num;}leftCol; // 左边界右移}direction (direction 1) % 4; // 切换方向}return arr;} } 另解 class Solution {public int[][] generateMatrix(int n) {int loop 0;  // 控制循环次数int[][] res new int[n][n];int start 0;  // 每次循环的开始点(start, start)int count 1;  // 定义填充数字int i, j; ​while (loop n / 2) { // 判断边界后loop从1开始// 模拟上侧从左到右for (j start; j n - loop; j) {res[start][j] count;} ​// 模拟右侧从上到下for (i start; i n - loop; i) {res[i][j] count;} ​// 模拟下侧从右到左for (; j loop; j--) {res[i][j] count;} ​// 模拟左侧从下到上for (; i loop; i--) {res[i][j] count;}start;} ​if (n % 2 1) {res[start][start] count;} ​return res;} }
http://www.hkea.cn/news/14479630/

相关文章:

  • 网站转app工具高级版网址怎么申请
  • 北京做网站比较有名的公司有哪些网站是做流程
  • 国内ui网站有哪些网页制作教程答案
  • 网站建设工单系统房子装修风格大全2021新款
  • 做一回最好的网站龙岗爱联有学网站建设
  • 深圳的设计企业网站提供专业网站建设平台
  • 有没有可以做翻译的网站wordpress 微站
  • 一个店铺的运营方案seo加盟代理
  • 八爪鱼网站建设中国民政网站医院标准化建设
  • 开发一个网站 要多久百度地图网页版
  • 做旅游网约车的网站中国战略咨询公司排名
  • 电子商务网站建设与管理论文网页素材提取
  • dedecms 模版网站wordpress 发货
  • 成都捕鱼网站建设陕西省建设监理协会查询官方网站
  • h5 建站网站 移动端做卖挖掘机的网站
  • 保定市做网站制作网站结构设计
  • 做网站价格中核工建设集团有限公司网站
  • python 做的网站有哪些链接怎么做
  • 查询网网站毕业答辩ppt模板免费下载 素材
  • 游戏网站做关键字做3d图的网站有哪些软件
  • 网站优化是做什么的wordpress默认相册图片连接到媒体
  • 可以自己做网站吗企业oa系统下载
  • 济南建网站品牌自适应网站建设
  • 建筑网站建设赏析免费网站下载大全
  • 企业做网站公司排名口碑详情页设计策划
  • 更新网站的步骤wordpress建站如何微信
  • 花生壳动态域名做网站做两个阿里网站吗
  • 云网站建设017年青吴忠市建设工程质量监督站网站
  • 怎么知道网站哪家公司做的网络营销导向的网站建设
  • 文化网站前置审批定位网站关键词