面试题67:机器人的运动范围
来源:互联网 发布:兄弟连nginx视频教程 编辑:程序博客网 时间:2024/05/17 09:05
public class Solution { public int movingCount(int threshold, int rows, int cols) { boolean flag[]=new boolean[rows*cols]; int count=movingCountCore(threshold,rows,cols,0,0,flag); return count; } public int movingCountCore(int threshold, int rows, int cols,int row,int col,boolean[] flag){ int count=0; if(check(threshold,rows,cols,row,col,flag)){ flag[row*cols+col]=true; count=1+movingCountCore(threshold,rows,cols,row-1,col,flag) +movingCountCore(threshold,rows,cols,row+1,col,flag) +movingCountCore(threshold,rows,cols,row,col-1,flag) +movingCountCore(threshold,rows,cols,row,col+1,flag); } return count; } public boolean check(int threshold,int rows,int cols,int row,int col,boolean[] flag){ if(row<rows&&row>=0&&col<cols&&col>=0&&getDig(row)+getDig(col)<=threshold&&!flag[row*cols+col]){ return true; } return false; } public int getDig(int num){ int sum=0; while(num>0){ sum+=num%10; num/=10; } return sum; }}
阅读全文
0 0
- 面试题67:机器人的运动范围
- 面试题67:机器人的运动范围
- 面试题67:机器人的运动范围
- 面试题74:机器人的运动范围
- 面试题67. 机器人的运动范围
- 【剑指Offer学习】【面试题67:机器人的运动范围】
- 《剑指offer》面试题67 机器人的运动范围
- 剑指offer--面试题67:机器人的运动范围
- 剑指offer-面试题67-机器人的运动范围
- 【剑指Offer】面试题67:机器人的运动范围
- 剑指offer--面试题13:机器人的运动范围
- 【剑指offer】面试题13:机器人的运动范围
- 《剑指Offer》学习笔记--面试题67:机器人的运动范围
- 剑指Offer面试题67:机器人的运动范围 Java实现
- 剑指Offer面试题13:机器人的运动范围 Java实现
- 机器人的运动范围
- 机器人的运动范围
- 机器人的运动范围
- 对话框最小尺寸的限制
- ubuntu 14.04 安装有道词典
- JAVA 面试题 输出100以内的所有素数
- WC命令详解
- Git忽略规则及.gitignore规则不生效的解决办法
- 面试题67:机器人的运动范围
- VM无法启动Ubuntu
- CSS3 选择器
- 设计模式原则(3):依赖倒置原则
- Android常用工具之对字符串String进行MD5加密
- Python中关于decode、encode以及编码方式
- Android之多线程解析(二)之Runnable、Callable、FutureTask
- python之路——字符串操作
- LibSVM