首页 > 其他分享 >322. Coin Change刷题笔记

322. Coin Change刷题笔记

时间:2023-05-26 22:02:54浏览次数:37  
标签:coin return int coins 322 amount Change Coin dp


用自底向上的dp算法

class Solution:
    def coinChange(self, coins: List[int], amount: int) -> int:
        dp = [0] + [float('inf')]*amount
        for i in range(1,amount+1):
            for coin in coins:
                if i-coin >= 0:
                    dp[i] = min(dp[i],dp[i-coin]+1)
                    
        if dp[-1]>100000:
            return -1
        else:
            return dp[-1]

322. Coin Change刷题笔记_leetcode


标签:coin,return,int,coins,322,amount,Change,Coin,dp
From: https://blog.51cto.com/u_16131692/6359377

相关文章

  • Django - makemigrations - No changes detected
    Django-makemigrations-Nochangesdetected回答1Tocreateinitialmigrationsforanapp,runmakemigrationsandspecifytheappname.Themigrationsfolderwillbecreated../manage.pymakemigrations<myapp>YourappmustbeincludedinINSTALLED......
  • el-select @change绑定item对象
    正常写,注意的是需要在<el-select>标签上加一个属性value-key,把<el-option>的key赋值给他,如下图。  ......
  • Exchange EMS 迁移用户邮箱
    查看邮箱数据库里所有的用户邮箱Get-Mailbox-DatabaseDB01获取邮箱数据库系统邮箱:Get-Mailbox-arbitration-DatabaseDB01将邮箱数据库testDB上的用户邮箱迁移至邮箱数据库testDB2:Get-Mailbox-DatabasetestDB|New-MoveRequest-TargetDatabasetestDB2查看迁移请求完成......
  • How to change the default Python2 to Python3 on Linux All In One
    HowtochangethedefaultPython2toPython3onLinuxAllInOneRaspberryPi在Linux中如何把默认的Python2更改为Python3solutions.bashrc/.zshrcalias$sudovim.bashrc$cat.bashrc$cat.bashrc|greppy#.bashrc配置一个alias✅#Python3=......
  • el-input的input和change事件区别
    inputinput是在输入值变化后就会触发changechange是在输入值变化并且失去焦点或用户按Enter时触发。与blur事件有着相似的功能,但与blur事件不同的是,change事件在输入框的值未改变时并不会触发blur不管输入值是否变化,只要失去焦点就会触发......
  • Golang的viper包调用多次OnConfigChange
    问题:修改了一次,而执行了两次这个函数解决方案把配置文件进行md5,保存其md5值。在调用这个函数时,再次读取文件进行md5。两者比对,如果相等就不执行下面的逻辑。这样就解决了,一模一样的配置文件,保存多次,不会执行后续的逻辑。但是,杜绝了大部分的场景,比如修改了一次,保存了两次......
  • day45| 70+322+279
    70.爬楼梯 题目简述:假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 思路:1.要想爬到第n阶,必须先上第n-1阶或者n-2阶2.利用动态规划,定义初始条件dp[0]=1,dp[1]=23.有dp[i]=dp[i-1]+dp[i-2],其中i......
  • python使用exchangelib读取、保存exchange邮件
    importosfromdatetimeimportdatetimeimportpytzfromexchangelibimportCredentials,Account,Configuration,DELEGATE,Q,FileAttachmentdefreceived_exchange_message():"""接收exchange邮件,保存邮件到本地:return:""......
  • github报错“ssh_exchange_identification: Connection closed by remote host fatal:
    解决方式:不确定是否为密钥过期还是C:\Users\John\.ssh文件夹下的config文件中没有添加github的host。总之,所有的尝试如下:(1)重新生成公钥和私钥。打开gitbash,输入以下命令获取自己github的email。gitconfiguser.email 生成ssh私钥和公钥ssh-keygen-trsa-......
  • Microsoft.Exchange.WebServices.Data;
    using Microsoft.Exchange.WebServices.Data;using Microsoft.Identity.Client;using System;using System.Configuration; namespace EwsOAuth{   class Program  {     static async System.Threading.Tasks.Task Main(string[] args) ......