Giter Club home page Giter Club logo

Comments (4)

silencemao avatar silencemao commented on June 6, 2024 2

没有错误,当length<=3的时候,我们直接返回了结果。如果整个绳子的长度为3,我们必须把绳子剪开,因为题目要求m>1,其中一段为2,另一段为1,这样结果就是2。
     当length>=4的时候,我们可以把绳子剪成两段,其中一段为3另一段为1,这样长度为3的那一段的最大值就是3而不是2,因为这一段我们不需要再剪了。当然长度为4的最大值是2和2的组合,我们已经存储了2的长度。

from codinginterviewchinese2.

L5411 avatar L5411 commented on June 6, 2024
if(length < 2)  return 0;
if(length == 2) return 1;
if(length == 3)  return 2;

这里是长度的返回值

products[1] = 1;
products[2] = 2;
products[3] = 3;

这些值是用来计算后续答案的,正确的值在开始时已经返回,后续计算需要用到 products[2]、products[3],比如 f(5) = f(2) * f(3) = 2 * 3,是不能等于 1 * 2 的

from codinginterviewchinese2.

kyolxs avatar kyolxs commented on June 6, 2024

没有错误,当length<=3的时候,我们直接返回了结果。如果整个绳子的长度为3,我们必须把绳子剪开,因为题目要求m>1,其中一段为2,另一段为1,这样结果就是2。
     当length>=4的时候,我们可以把绳子剪成两段,其中一段为3另一段为1,这样长度为3的那一段的最大值就是3而不是2,因为这一段我们不需要再剪了。当然长度为4的最大值是2和2的组合,我们已经存储了2的长度。

谢谢大佬

from codinginterviewchinese2.

zhedahht avatar zhedahht commented on June 6, 2024

谢谢silencemao的解释。

from codinginterviewchinese2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.