File tree 1 file changed +4
-6
lines changed
src/main/java/com/thealgorithms/dynamicprogramming
1 file changed +4
-6
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
11
- MaximumSumOfNonAdjacentElements () {}
10
+
11
+ private MaximumSumOfNonAdjacentElements () {}
12
12
13
13
/**
14
14
* Approach 1: Uses a dynamic programming array to store the maximum sum at
@@ -17,8 +17,7 @@ final class MaximumSumOfNonAdjacentElements {
17
17
* @param arr The input array of integers.
18
18
* @return The maximum sum of non-adjacent elements.
19
19
*/
20
- public
21
- static int getMaxSumApproach1 (int [] arr ) {
20
+ public static int getMaxSumApproach1 (int [] arr ) {
22
21
int n = arr .length ;
23
22
int [] dp = new int [n ];
24
23
@@ -53,8 +52,7 @@ static int getMaxSumApproach1(int[] arr) {
53
52
* @param arr The input array of integers.
54
53
* @return The maximum sum of non-adjacent elements.
55
54
*/
56
- public
57
- static int getMaxSumApproach2 (int [] arr ) {
55
+ public static int getMaxSumApproach2 (int [] arr ) {
58
56
int n = arr .length ;
59
57
60
58
// Two variables to keep track of previous two results:
You can’t perform that action at this time.
0 commit comments