当前位置:网站首页>【JZOF】13机器人的运动范围
【JZOF】13机器人的运动范围
2022-07-23 15:55:00 【叹了口丶气】

import java.util.*;
public class Solution {
public int movingCount(int threshold, int rows, int cols)
{
int[] visited = new int[rows*cols];
return movingHelper(threshold,rows,cols,0,0,visited);
}
public int movingHelper(int threshold, int rows,int cols,int row, int col, int[] visited){
int count =0;
if(canReach(threshold,rows,cols,row,col,visited)){
visited[row*cols+col]=1;
count = 1+movingHelper(threshold,rows,cols,row-1,col,visited)
+movingHelper(threshold,rows,cols,row+1,col,visited)
+movingHelper(threshold,rows,cols,row,col-1,visited)
+movingHelper(threshold,rows,cols,row,col+1,visited);
}
return count;
}
public boolean canReach(int threshold, int rows, int cols, int row, int col, int[] visited){
if(row>=0 && row<rows && col<cols && col>=0 && visited[row*cols+col]==0 && getDigitSum(row)+getDigitSum(col)<=threshold)
return true;
else
return false;
}
public int getDigitSum(int num){
int sum =0;
while(num!=0){
sum = sum+ (num%10);
num = num/10;
}
return sum;
}
}
边栏推荐
猜你喜欢

Activity Registration: how to quickly start the open source tapdata live data platform on a zero basis?

MySQL事务,从redo log、bin log、undo log说起...

B端市场复苏背后:谁站到台前?

go中高并发下的通信方式:channel管道的底层原理

网分测花岗岩介电常数测试方案

Static distribution and dynamic distribution in trust
![[216] go language standard library package name](/img/14/bd12be4204ed44e114b1311f08c9e3.jpg)
[216] go language standard library package name

CSDN custom T-shirts are waiting for you to get, and the benefits of new programmer are coming!

Mutual certification of product compatibility between tapdata and Youxuan database

Sentinel introduction and microservice integration
随机推荐
Docker installs redis and starts it as a configuration file
B端市场复苏背后:谁站到台前?
(十一)STM32——IO引脚复用与映射
MySQL foundation and performance optimization
Eric6 installation problem
MySQL uses commands to export and import in Windows
Analyze the CPU surge of an RFID tag system written by.Net
Activity Registration: how to quickly start the open source tapdata live data platform on a zero basis?
机器学习(9)——特征工程(3)(补充)
本周一问 | Vivado 综合阶段什么约束生效?
LeetCode_ Dynamic programming_ Medium_ 120. Triangle minimum path sum
Seata
Detailed explanation of CO process principle in go
gom及gee架设黑屏的原因以及个别装备地图不显示怎么办?
RS232 DB9 serial port device
Machine learning (9) - Feature Engineering (3) (supplementary)
Parameters of mysqldump
leetcode:剑指 Offer II 115. 重建序列【图论思维 + 入度考虑 + 拓扑排序】
go中的協程原理詳解
Calculus of variations