每天刷一道牛客题霸-第24天- 换钱最少货币数

题目

https://www.nowcoder.com/practice/3911a20b3f8743058214ceaa099eeb45?tpId=190&&tqId=36067&rp=1&ru=/activity/oj&qru=/ta/job-code-high-rd/question-ranking

import java.util.*;


public class Solution {
    /**
     * 最少货币数
     * @param arr int整型一维数组 the array
     * @param aim int整型 the target
     * @return int整型
     */
   public static int minMoney (int[] arr, int aim) {
        int[] count = new int[aim +1];
        Arrays.fill(count, aim + 1);
        count[0] = 0;
        for (int i =1;i<=aim;i++){
            for (int j = 0 ; j < arr.length ; j++){
                if (i >=arr[j]){
                    count[i] = Math.min(count[i-arr[j]] +1 , count[i]);
                }
            }
        }
        return count[aim] != aim+1 ? count[aim] :-1;
        // write code here
    }
}
#牛客题霸##题解#
全部评论
点赞 回复 分享
发布于 2021-01-06 20:32

相关推荐

King987:在校生的话建议把在校经历丰富一下,多写一些比赛。项目简介中你的项目描述太长了,多写几个技术点。必须要是亮点让面试官有的问,他就会通过你的简历,自己改一改再投面试会多一些,改不好可以聊我
点赞 评论 收藏
分享
EEbond:给北邮✌️跪了
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

更多
牛客网
牛客企业服务