problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::coin_change::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int coinChange (vector< int > &coins, int amount)
 

详细描述

在文件 leetcode.h2531 行定义.

成员函数说明

◆ coinChange()

int leetcode::coin_change::Solution::coinChange ( vector< int > &  coins,
int  amount 
)
static

在文件 leetcode.cpp6805 行定义.

6805 {
6806 vector dp(amount + 1, -1);
6807 dp[0] = 0;
6808 for(const auto &coin: coins) {
6809 if(coin <= amount) {
6810 dp[coin] = 1;
6811 }
6812 }
6813 for(unsigned i = 0; i <= amount; i++) {
6814 if(dp[i] > 0) {
6815 for(const auto &coin: coins) {
6816 if(i + coin <= static_cast<unsigned>(amount)) {
6817 if(dp[i + coin] == -1) {
6818 dp[i + coin] = dp[i] + 1;
6819 } else {
6820 dp[i + coin] = min(dp[i + coin], dp[i] + 1);
6821 }
6822 }
6823 }
6824 }
6825 }
6826 return dp[amount];
6827 }

被这些函数引用 leetcode::coin_change::TEST().


该类的文档由以下文件生成: