1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| class Solution { int count = 0;
public int numWays(int n, int[][] relation, int k) { dfs(0, n, relation, k); return count; }
public void dfs(int cur, int n, int[][] relation, int k) { if (k == 0 && cur == n - 1) { count++; return; }
if (k < 0) { return; }
for (int[] arr : relation) { if (cur == arr[0]) { dfs(arr[1], n, relation, k-1); } } } }
|