1
+ // Runtime: 5 ms (Top 88.89%) | Memory: 40.7 MB (Top 100.00%)
1
2
class Solution {
2
- int bobPoint = 0 ;
3
- int [] maxbob = new int [12 ];
4
- public int [] maximumBobPoints (int numArrows , int [] aliceArrows ) {
5
- int [] bob = new int [12 ];
6
- calculate (aliceArrows , bob , 11 , numArrows , 0 ); //Start with max point that is 11
7
- return maxbob ;
8
- }
9
- public void calculate (int [] alice , int [] bob , int index , int remainArr , int point ) {
10
- if (index < 0 || remainArr <= 0 ) {
11
- if (remainArr > 0 )
12
- bob [0 ] += remainArr ;
13
- if (point > bobPoint ) { // Update the max points and result output
14
- bobPoint = point ;
15
- maxbob = bob .clone ();
16
- }
17
- return ;
18
- }
19
- //part 1: assign 1 more arrow than alice
20
- if (remainArr >= alice [index ]+1 ) {
21
- bob [index ] = alice [index ] + 1 ;
22
- calculate (alice , bob , index -1 , remainArr -(alice [index ]+1 ), point + index );
23
- bob [index ] = 0 ;
24
- }
25
- //part 2: assign no arrow and move to next point
26
- calculate (alice , bob , index -1 , remainArr , point );
27
- bob [index ] = 0 ;
28
- }
29
- }
3
+ int bobPoint = 0 ;
4
+ int [] maxbob = new int [12 ];
5
+ public int [] maximumBobPoints (int numArrows , int [] aliceArrows ) {
6
+ int [] bob = new int [12 ];
7
+ calculate (aliceArrows , bob , 11 , numArrows , 0 ); //Start with max point that is 11
8
+ return maxbob ;
9
+ }
10
+ public void calculate (int [] alice , int [] bob , int index , int remainArr , int point ) {
11
+ if (index < 0 || remainArr <= 0 ) {
12
+ if (remainArr > 0 )
13
+ bob [0 ] += remainArr ;
14
+ if (point > bobPoint ) { // Update the max points and result output
15
+ bobPoint = point ;
16
+ maxbob = bob .clone ();
17
+ }
18
+ return ;
19
+ }
20
+ //part 1: assign 1 more arrow than alice
21
+ if (remainArr >= alice [index ]+1 ) {
22
+ bob [index ] = alice [index ] + 1 ;
23
+ calculate (alice , bob , index -1 , remainArr -(alice [index ]+1 ), point + index );
24
+ bob [index ] = 0 ;
25
+ }
26
+ //part 2: assign no arrow and move to next point
27
+ calculate (alice , bob , index -1 , remainArr , point );
28
+ bob [index ] = 0 ;
29
+ }
30
+ }
0 commit comments