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

贪心算法:根据身高重建队列(续集)——应该使用 vector::reserve 函数来指定 vector 的 capacity! #2687

Open
HuangDuoYan opened this issue Aug 12, 2024 · 0 comments

Comments

@HuangDuoYan
Copy link

那么是不是可以直接确定好vector的大小,不让它在动态扩容了

原来的代码通过在构造函数中设置大小,导致后面过程非常繁琐。
应该考虑使用无参构造函数定义结果队列 que,然后用 que.reserve(people.size()); 语句一次性分配空间,指定 capacity!

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

1 participant