题目:小猴子下山,沿着下山的路有一排桃树,每棵树都结了一些桃子。小猴子想摘桃子,但是有一些条件需要遵守,小猴子只能沿着下 山的方向走,不能...
package com.hp.algorithm.mostpeach; import java.util.ArrayList;import java.util.List;public class MostPeach{ public static int currMaxPeachNum = 0;//当前摘的最大一颗树 public static int mostPeach(List<Integer> treeWithPeach){ if(null == treeWithPeach){ return 0; } if(1 == treeWithPeach.size()){ if(currMaxPeachNum > treeWithPeach.get(0)){ return 0; } return 1; } int pick = 0; int notPick = 0; if(currMaxPeachNum <= treeWithPeach.get(0)){ //情况1:当前桃子树大于currMaxPeachNum,摘。摘了之后还要摘后面的树 currMaxPeachNu...