The Wayback Machine - https://web.archive.org/web/20201031071346/https://github.com/halfrost/LeetCode-Go/issues/78
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

问一个关于746. Min Cost Climbing Stairs的问题 #78

Open
vivozhitao opened this issue Oct 25, 2020 · 5 comments
Open

问一个关于746. Min Cost Climbing Stairs的问题 #78

vivozhitao opened this issue Oct 25, 2020 · 5 comments

Comments

@vivozhitao
Copy link

@vivozhitao vivozhitao commented Oct 25, 2020

首先感谢halfrost以及大家的贡献。我在看746题的过程中,觉得第一个example的答案应该是10吧?就是我可以先从index=0开始,然后付费后,选择走两步阶梯到达顶端,不知道我的理解哪里有错?谢谢。

@halfrost
Copy link
Owner

@halfrost halfrost commented Oct 26, 2020

@vivozhitao
Copy link
Author

@vivozhitao vivozhitao commented Oct 26, 2020

但是题目中的原话是:Once you pay the cost, you can either climb one or two steps。意思就是,如果我站在0层,先支付了10,那就可以选择climb two steps,于是就到了顶层?

@halfrost
Copy link
Owner

@halfrost halfrost commented Oct 27, 2020

但是题目中的原话是:Once you pay the cost, you can either climb one or two steps。意思就是,如果我站在0层,先支付了10,那就可以选择climb two steps,于是就到了顶层?

@vivozhitao 站在0层,先支付了10,爬 2 步以后,到达的是第 2 层,并非顶层。数组下标 2 的位置还有一个 cost,说明往上爬到顶层还需要再花费 20 。你应该是对顶层的这个理解出错了。数组最后一个元素并不是顶层,还需要再往上爬。

@vivozhitao
Copy link
Author

@vivozhitao vivozhitao commented Oct 28, 2020

但是题目中的原话是:Once you pay the cost, you can either climb one or two steps。意思就是,如果我站在0层,先支付了10,那就可以选择climb two steps,于是就到了顶层?

@vivozhitao 站在0层,先支付了10,爬 2 步以后,到达的是第 2 层,并非顶层。数组下标 2 的位置还有一个 cost,说明往上爬到顶层还需要再花费 20 。你应该是对顶层的这个理解出错了。数组最后一个元素并不是顶层,还需要再往上爬。

哦,原来如此!多谢!这个真是很容易误解~~~

@halfrost
Copy link
Owner

@halfrost halfrost commented Oct 28, 2020

@vivozhitao 我当时针对第一个 example 也考虑了一下。我和你想的一样,但是我看到数组里面下标 2 的地方还有值,我就猜测,到了 2 楼以后,还不是顶楼,因为还有 cost 需要支付。所以题目中的顶楼是比数组里面元素多 1 的。到了顶楼,自然不需要 cost 了,所以顶楼也就不在数组里面了。我就按照我这个想法尝试了写了一版,就 AC 了。也验证了题目就是这个意思 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.