@Test public void findMaxUnContinuousSum() { int[] array = {1, 5, 2, 1, 7}; int predictSum = 12; assert predictSum == DataUtil.findMaxUnContinuousSum(array); }
public static int findMaxUnContinuousSum(int[] array) { if (array == null || array.length == 0) { return 0; } int[] dp = new int[array.length + 1]; dp[0] = 0; dp[1] = array[0]; for (int i = 2; i <= array.length; i++) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + array[i - 1]); } return dp[array.length]; }
DataUtil { public static int findMaxUnContinuousSum(int[] array) { if (array == null || array.length == 0) { return 0; } int[] dp = new int[array.length + 1]; dp[0] = 0; dp[1] = array[0]; for (int i = 2; i <= array.length; i++) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + array[i - 1]); } return dp[array.length]; } }
DataUtil { public static int findMaxUnContinuousSum(int[] array) { if (array == null || array.length == 0) { return 0; } int[] dp = new int[array.length + 1]; dp[0] = 0; dp[1] = array[0]; for (int i = 2; i <= array.length; i++) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + array[i - 1]); } return dp[array.length]; }  }
DataUtil { public static int findMaxUnContinuousSum(int[] array) { if (array == null || array.length == 0) { return 0; } int[] dp = new int[array.length + 1]; dp[0] = 0; dp[1] = array[0]; for (int i = 2; i <= array.length; i++) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + array[i - 1]); } return dp[array.length]; }  static int getMatrixHeavy(int[][] matrix, int m, int n); static int maxSequenceSum(int[] array); static int fibonacciRecursive(int n); static int fibonacci(int n); static int findMaxUnContinuousSum(int[] array); static void findContinuousSequenceMethod1(int n); static void findContinuousSequenceMethod2(int n); static void findContinuousSequenceMethod3(int n); static void findContinuousSequenceMethod4(int n); static void pickNum(int[] originArray, int n, int m, int[] selectArray, int startIndex, boolean inorder); static int binarySearch(int[] array, int key); static int findFirstEqual(int[] array, int key); static int findFirstEqualLarger(int[] array, int key); static int findFirstLarger(int[] array, int key); static int findLastEqual(int[] array, int key); static int findLastEqualSmaller(int[] array, int key); static List<Integer> shufflePump(List<Integer> origin); static List<Integer> shuffleSwap(List<Integer> origin); static int[] shuffleSwap(int[] origin); static String getAccurateDivide(int a, int b, int n); static Set<Integer> getPrimeNumInefficient(int range); static Set<Integer> getPrimeNumEfficient(int range); static int getIntervalDays(int year, int month, int day); static int pageHelper(int n, int m); static boolean isOdd(int num); }
DataUtil { public static int findMaxUnContinuousSum(int[] array) { if (array == null || array.length == 0) { return 0; } int[] dp = new int[array.length + 1]; dp[0] = 0; dp[1] = array[0]; for (int i = 2; i <= array.length; i++) { dp[i] = Math.max(dp[i - 1], dp[i - 2] + array[i - 1]); } return dp[array.length]; }  static int getMatrixHeavy(int[][] matrix, int m, int n); static int maxSequenceSum(int[] array); static int fibonacciRecursive(int n); static int fibonacci(int n); static int findMaxUnContinuousSum(int[] array); static void findContinuousSequenceMethod1(int n); static void findContinuousSequenceMethod2(int n); static void findContinuousSequenceMethod3(int n); static void findContinuousSequenceMethod4(int n); static void pickNum(int[] originArray, int n, int m, int[] selectArray, int startIndex, boolean inorder); static int binarySearch(int[] array, int key); static int findFirstEqual(int[] array, int key); static int findFirstEqualLarger(int[] array, int key); static int findFirstLarger(int[] array, int key); static int findLastEqual(int[] array, int key); static int findLastEqualSmaller(int[] array, int key); static List<Integer> shufflePump(List<Integer> origin); static List<Integer> shuffleSwap(List<Integer> origin); static int[] shuffleSwap(int[] origin); static String getAccurateDivide(int a, int b, int n); static Set<Integer> getPrimeNumInefficient(int range); static Set<Integer> getPrimeNumEfficient(int range); static int getIntervalDays(int year, int month, int day); static int pageHelper(int n, int m); static boolean isOdd(int num);  }