Maximum Sum of Non-adjacent Elements in 1D array

后端 未结 4 556
小蘑菇
小蘑菇 2021-01-27 09:30

Given an array of integers, find a maximum sum of non-adjacent elements. For example, inputs [1, 0, 3, 9, 2,-1] should return 10 (1 + 9).

4条回答
  •  既然无缘
    2021-01-27 10:12

    package abc;

    public class Solution {

    // int[] A{1,4,5,2,5,4,2}

    public int nonAdjacentMaxSumRepeated(int[] inpArray) {
    
        int[] a = new int[inpArray.length];
        int k=0;
        for(int i=0,j=0;i

    }

提交回复
热议问题