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

政府网站栏目设计原则/网络软文

政府网站栏目设计原则,网络软文,门户网站建设及运营,鞍山信息港家讯房产一、思路 这个题目主要有两个问题,一是什么时候切换方向,二是如何切换方向 问题一:此步移动完后,判断下一个元素,如果大于等于边界值(从0开始)或者小于边界值时或者访问数组为真时 问题二&am…

一、思路

这个题目主要有两个问题,一是什么时候切换方向,二是如何切换方向

问题一:此步移动完后,判断下一个元素,如果大于等于边界值(从0开始)或者小于边界值时或者访问数组为真时

问题二:创建一个方向数组,通过行数和列数的加减来实现切换方向,然后通过%4来循环访问这个数组

二、记忆

1.二维矩阵的使用长度声明和直接用数值定义

int[][] check = new int[rows][columns];
int[][] nextdirections ={{0,1},{1,0},{0,-1},{-1,0}};

2.方向数组来确定移动方向的思路

3.预判定的思路

int nextrow = row + nextdirections[nextdirection][0];
int nextcolumn = column + nextdirections[nextdirection][1];
if(nextcolumn>=columns || nextcolumn<0 || nextrow<0 || nextrow>=rows || check[nextrow][nextcolumn] ==1 ){nextdirection = (nextdirection+1)%4;
}

三、代码

public List<Integer> spiralOrder(int[][] matrix){ArrayList<Integer> order = new ArrayList<>();//异常条件处理if(matrix == null || matrix.length == 0 || matrix[0].length ==0) return order;int rows = matrix.length,columns = matrix[0].length;int[][] check = new int[rows][columns];int[][] nextdirections ={{0,1},{1,0},{0,-1},{-1,0}};int total = rows*columns;int row = 0,column = 0;int nextdirection = 0;for(int i = 0;i<total;i++){order.add(matrix[row][column]);check[row][column] = 1;//预判,确定移动方向int nextrow = row + nextdirections[nextdirection][0];int nextcolumn = column + nextdirections[nextdirection][1];if(nextcolumn>=columns || nextcolumn<0 || nextrow<0 || nextrow>=rows || check[nextrow][nextcolumn] ==1 ){nextdirection = (nextdirection+1)%4;}//移动row += nextdirections[nextdirection][0];column += nextdirections[nextdirection][1];}return order;}

http://www.jinmujx.cn/news/454.html

相关文章:

  • app设计网站模板/google优化师
  • 做网站月收入多少/百度网站推广
  • 如何建立和设计公司网站作文/百度快速seo优化
  • 邢台路桥建设总公司没有网站吗/宣传软文范例
  • 商城网站建设视频教程/关键词排名优化教程
  • 网站seo做哪些工作/seo引擎优化培训
  • 广州乐地网站建设/网络营销成功的案例及其原因
  • ppt模板制作教程步骤/360优化大师旧版
  • 贵州省住房和城乡建设管理委员会网站/成都seo培
  • 无锡网站建设企业排名/友情链接交易
  • wordpress 目录改变/网络优化师
  • 福州建设委员会网站/福建网站建设制作
  • 服务器做网站空间/网店培训骗局
  • 网页游戏网站建设/汕头seo优化项目
  • 郑州网站建设哪家公司好/新品上市的营销方案
  • 网站上的销售怎么做的/百度网盘私人资源链接
  • 做网站挂靠服务器什么好/类聚seo
  • 百度网址大全导航首页/九江seo公司
  • 企业网站模板免费版/百度一下网页版浏览器
  • 网站结构与导航设计/石景山区百科seo
  • 做网站用什么ps软件/朋友圈营销
  • 沭阳奥体小区做网站/广州专业网络推广公司
  • 申报城市维护建设税上哪个网站/网站运营工作内容
  • 武义网站建设/互联网营销师培训机构
  • 公益网站建设需求/大数据分析师
  • 沈阳网站建设建设公司/怎么创建网站平台
  • 霸州放心的网络建站/爱战网关键词查询网站
  • 宁波免费网页制作模板/曹操博客seo
  • app store官方正版下载/班级优化大师简介
  • 怎么防止网站被镜像/nba赛季排名