File tree 2 files changed +46
-0
lines changed 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int numWays (int n , int [][] relation , int k ) {
3
+ int [][] dp = new int [k + 1 ][n + 1 ];
4
+ for (int i = 0 ;i < relation .length ;i ++){
5
+ if (relation [i ][0 ] == 0 ){
6
+ dp [1 ][relation [i ][1 ]] = 1 ;
7
+ }
8
+ }
9
+ for (int i = 2 ; i <=k ; i ++){
10
+ for (int j = 0 ;j < n ; j ++){
11
+ for (int l = 0 ; l < relation .length ; l ++){
12
+ if (relation [l ][1 ] == j ){
13
+ dp [i ][j ] += dp [i - 1 ][relation [l ][0 ]];
14
+ }
15
+ }
16
+ }
17
+ }
18
+ return dp [k ][n - 1 ];
19
+ }
20
+ }
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public int [] getTriggerTime (int [][] increase , int [][] requirements ) {
3
+ int [] res = new int [requirements .length ];
4
+ for (int i = 1 ;i < increase .length ; i ++){
5
+ increase [i ][0 ] +=increase [i -1 ][0 ];
6
+ increase [i ][1 ] +=increase [i -1 ][1 ];
7
+ increase [i ][2 ] +=increase [i -1 ][2 ];
8
+ }
9
+ for (int i = 0 ; i < requirements .length ; i ++){
10
+ for (int j = 0 ; j < increase .length ;j ++){
11
+ if (requirements [i ][0 ] == 0 && requirements [i ][1 ] == 0 &&requirements [i ][2 ] == 0 ){
12
+ res [i ] = 0 ;
13
+ break ;
14
+ }
15
+ if (increase [j ][0 ] >= requirements [i ][0 ] && increase [j ][1 ] >= requirements [i ][1 ] && increase [j ][2 ] >= requirements [i ][2 ] ){
16
+ res [i ] = j + 1 ;
17
+ break ;
18
+ }
19
+ if (j == increase .length - 1 ){
20
+ res [i ] = -1 ;
21
+ }
22
+ }
23
+ }
24
+ return res ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments