赞
踩
- public class match {
- public static void main(String[] args) {
- Solution666 s=new Solution666();
- int[][] i=new int[][]{{1,2,3},{4,5,6},{7,8,9}};
- s.dfs(i,0,0);
- }
- }
- class Solution666 {
- public void dfs(int[][] grid, int i, int j){
- if(i < 0 || j < 0 || i >= grid.length || j >= grid[0].length||grid[i][j]==0){
- return;
- }
- System.out.println(grid[i][j]);
- grid[i][j]=0;
- //grid[i][j]=0;
- dfs(grid, i + 1, j);
- dfs(grid, i, j + 1);
- dfs(grid, i - 1, j);
- dfs(grid, i, j - 1);
- }
- }
这里说明一下dfs调用栈顺序
第一行进入递归后,这个栈下面最后回溯
递归到底执行到底情况的第二个递归
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。