标签:进入 turn 成功 div color 坐标 || 思路 sum
public class Solution { public int movingCount(int threshold, int rows, int cols) { int visited[][] = new int[rows][cols]; return helper(threshold, rows, cols, 0, 0, visited); } public int helper(int threshold, int rows, int cols, int i, int j, int[][] visited) { if(i<0||i>=rows||j<0||j>=cols||visited[i][j]==1||(bitSum(i)+bitSum(j))>threshold) return 0; visited[i][j] = 1; return helper(threshold, rows, cols, i+1, j, visited) + helper(threshold, rows, cols, i-1, j, visited) + helper(threshold, rows, cols, i, j+1, visited) + helper(threshold, rows, cols, i, j-1, visited)+1; } public int bitSum(int t) { int count = 0; do{ count += t % 10; t = t/10; }while(t > 0); return count; } }
标签:进入 turn 成功 div color 坐标 || 思路 sum
原文地址:https://www.cnblogs.com/yihangZhou/p/10545674.html