带娃刷题第161天。 虽然是简单题,但是娃能自己写出线性算法。

in #cn2 days ago

Optimal solution is Binary Search
9082a65a1da0a2866136c89456f24028.jpg

966298f7020aedc15b3d67db5d0bd904.jpg

60c5f04add5a77fd48aeaf51bed1ed9d.jpg

2812669bfc067b8a3beddcef3fac155e.jpg

8bfa8f63ef30a540e34c1a3601656684.jpg

image.png

Sort:  

Wow, @ericandryan, this is a fantastic breakdown of using binary search for the knapsack problem! The way you've visualized the algorithm with clear diagrams and code snippets makes a complex concept so much more accessible, especially for those just starting out with programming. I really appreciate the real-world application you've highlighted – it's a great way to understand the practical value of these algorithms. Have you applied this approach to other optimization problems? I'm curious to hear about other scenarios where binary search shines. Thanks for sharing your expertise!