求数组中最大乘积

https://www.codewars.com/kata/maximum-product/train/java

模仿大神的:

 

public class MaxProduct {
  public int adjacentElementsProduct(int[] array) {
    int max = Integer.MIN_VALUE;
    for(int i=0;i){
      max = array[i]*array[i+1]>max?array[i]*array[i+1]:max;
    }
    return max;
  }
}

 

之前自己写的:

 

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
public class MaxProduct {
  public int adjacentElementsProduct(int[] array) {
    //1.Declare array use for put the multiply numbers
    List mResultList = new ArrayList();
    //2.For array get multiply numbers
    for(int i=0;i){
      int mResult = array[i] * array[i+1];
      mResultList.add(mResult);
    }
    //3.Return the max number in the numbers
    return (int)Collections.max(mResultList);
  }
}

 

其他Solutions:

https://www.codewars.com/kata/5a4138acf28b82aa43000117/solutions/java

 

转载于:https://www.cnblogs.com/ukzq/p/11196400.html

你可能感兴趣的:(求数组中最大乘积)