File tree 1 file changed +7
-4
lines changed
src/main/java/com/thealgorithms/dynamicprogramming
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 7
7
* https://takeuforward.org/data-structure/maximum-sum-of-non-adjacent-elements-dp-5/
8
8
*/
9
9
final class MaximumSumOfNonAdjacentElements {
10
- private MaximumSumOfNonAdjacentElements () {}
10
+ private
11
+ MaximumSumOfNonAdjacentElements () {}
11
12
12
13
/**
13
14
* Approach 1: Uses a dynamic programming array to store the maximum sum at
@@ -16,7 +17,8 @@ private MaximumSumOfNonAdjacentElements() {}
16
17
* @param arr The input array of integers.
17
18
* @return The maximum sum of non-adjacent elements.
18
19
*/
19
- public static int getMaxSumApproach1 (int [] arr ) {
20
+ public
21
+ static int getMaxSumApproach1 (int [] arr ) {
20
22
int n = arr .length ;
21
23
int [] dp = new int [n ];
22
24
@@ -51,7 +53,8 @@ public static int getMaxSumApproach1(int[] arr) {
51
53
* @param arr The input array of integers.
52
54
* @return The maximum sum of non-adjacent elements.
53
55
*/
54
- public static int getMaxSumApproach2 (int [] arr ) {
56
+ public
57
+ static int getMaxSumApproach2 (int [] arr ) {
55
58
int n = arr .length ;
56
59
57
60
// Two variables to keep track of previous two results:
@@ -82,4 +85,4 @@ public static int getMaxSumApproach2(int[] arr) {
82
85
83
86
return prev1 ;
84
87
}
85
- }
88
+ }
You can’t perform that action at this time.
0 commit comments