package codingInterviewGuide.part4dp;/*** Created by Dell on 2017年08月10日.*/public class LeastNumExtend {public static int getNum(int[] arr,int aim){return voilence(arr,0,aim);}public static int voilence(int[] arr,int index,int aim){if(aim==0){return 0;}if(aim<0||index==arr.length){return -1;}int count=0,temp1=0,temp2=0;//有两种情况,分别递归temp1=voilence(arr,index+1,aim);temp2=voilence(arr,index+1,aim-arr[index]);temp2=temp2==-1?temp2:temp2+1;if(temp2!=-1&&temp1!=-1){return Math.min(temp1,temp2);}//两者都等于-1,或其中一个等于-1if(temp1==-1&&temp2==-1){return -1;}else{return temp1==-1?temp2:temp1;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。