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

asp新闻网站模板百度开户推广

asp新闻网站模板,百度开户推广,福州seo关键词排名,怀化网站建设怎么收费一、思路 这个题目主要有两个问题,一是什么时候切换方向,二是如何切换方向 问题一:此步移动完后,判断下一个元素,如果大于等于边界值(从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.fp688.cn/news/164907.html

相关文章:

  • web前端就业岗位网站如何做seo排名
  • vs2012解决方案做网站近三天的国内新闻
  • 二级网站域名在线建站模板
  • 高台县建设局网站电商平台运营
  • 重庆网站建设索q479185700关键词首页排名代做
  • 手机触屏网站天津seo排名收费
  • 怎样做软件网站建设成都网络营销推广
  • 网站被加黑链百度竞价推广怎么做效果好
  • 外国人做旅游攻略网站免费网站推广优化
  • 做二手网站好的名字app拉新接单平台
  • 北京专业网站建设网站抚州网站seo
  • 花都区pc端网站建设关键词优化排名平台
  • 城市分类信息网站建设怎样做网站的优化、排名
  • 影视网站设计论文个人接外包的网站
  • 阿里云上做网站套模板怎么做职业培训机构哪家最好
  • 网站建设 创新windows优化大师要钱
  • 长安公司网站建设网络广告营销策划方案
  • 网站建设图片怎么做市场推广和销售的区别
  • 自己做的网站能备案谷歌推广教程
  • 新乡网站建设费用谷歌浏览器app
  • 二手房网站平台怎么做最好的搜索引擎
  • 用小米路由器做网站关键词优化排名
  • 东莞企业黄页资料seo优化网站
  • wordpress页面编辑成2列长沙seo优化报价
  • 政府集约化网站建设建议google推广seo
  • 免备案域名免费申请百度seo怎么做网站内容优化
  • 昆山做网站的kamese百度一下 你就知道首页官网
  • 电话客服外包网店关键词怎么优化
  • 贵州省建设厅网站首页seo诊断专家
  • 17做网店网站池尾前端培训