@@ -45,32 +45,39 @@ This problem can be treat as a pyramid which shaped by 1, it looks like below:
45
45
1 1 1 1 1 1 1
46
46
So, from the top, for each layer, we need the 1,3,5,7,9.... 2*n-1 ONE(s).
47
47
48
- But we need to deal with the edge case - it could be out of the array bound
48
+ But we need to deal with the edge case - it could be out of the array boundary
49
49
50
50
For example: index=2, lenght=3, maxSum=18
51
51
52
52
1) at first, we put `1 1 1` on bottom layer - Array[2] = 1
53
53
54
- 2) then we start from the top - Array[2] = 2
54
+ 2) then we start from the top
55
55
56
56
1 <-- the top first layer
57
57
1 1 1 <-- bottom
58
+
59
+ now, we have Array[2] is 2
58
60
59
61
3) we keep doing tthe 2nd layer - Array[2] = 3
60
62
1 <-- the 1st layer
61
- 1 1 [1] <-- the 2nd layer, which has 1 out of the bound
63
+ 1 1 [1] <-- the 2nd layer, which has 1 out of the boundary
62
64
1 1 1 <-- bottom
65
+
66
+ now, we have Array[2] is 3
63
67
64
68
4) the 3rd layer - Array[2] = 4
65
69
1 <-- the 1st layer
66
- 1 1 [1] <-- the 2nd layer, which has 1 out of the bound
67
- 1 1 1 [1] [1] <-- the 3rd layer, which has 2 out of the bound
70
+ 1 1 [1] <-- the 2nd layer, which has 1 out of the boundary
71
+ 1 1 1 [1] [1] <-- the 3rd layer, which has 2 out of the boundary
68
72
1 1 1 <-- bottom
73
+
74
+ now, we have Array[2] is 4
69
75
70
- 5) Now, the rest layers no need to be cacluated, they all are `3`
71
- So far, we spent 9 of `1`, we still have 9, so 9/3 = 3
72
-
73
- 6) Finally, the maximum of Array[2] = 4 + 3 = 7
76
+ 5) Now, the rest layers no need to be cacluated, they all are `3`.
77
+ Since 4), we spent 9 of `1`, we still have 18 - 9 = 9 of `1`
78
+ So, we can have 9/3 = 3 layer.
79
+
80
+ 6) Finally, the maximum of Array[2] = 4 + 3 = 7
74
81
*/
75
82
76
83
class Solution {
0 commit comments