Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15.1 贪心算法例子 coin_change_greedy.js #1360

Closed
yuadh opened this issue May 13, 2024 · 1 comment
Closed

15.1 贪心算法例子 coin_change_greedy.js #1360

yuadh opened this issue May 13, 2024 · 1 comment

Comments

@yuadh
Copy link

yuadh commented May 13, 2024

请问这个例子是面向结果编程吗。 还是说贪心算法, 本就有可能得不到正确答案(即使用其它算法有解)。 例如带入 coinChangeGreedy([40,60,70],100) 去算,返回值为-1。 抛开时间复杂度和空间复杂度不谈,为什么得不到解,有点面向结果编程的意思。

@hpstory
Copy link
Contributor

hpstory commented May 14, 2024

Hi @yuadh , 这节后面的内容有介绍, 有些问题不适合使用贪心处理。对于硬币找零问题,在某些硬币组合下,贪心算法才可以得到最优解。

@krahets krahets closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants