繁体   English   中英

这种方法的复杂度是多少? [复制]

[英]What is this method complexity? [duplicate]

我很难确定这种方法的时间和空间复杂性。 你们中有人对像这样的递归案例有任何提示吗? 因为我觉得他们真的很棘手

class Program {

  public int staircaseTraversal(int height, int maxSteps) {
    return staircaseTraversalRec(height, maxSteps, 0, 0);
  }

  public int staircaseTraversalRec(int height, int maxSteps, int currentHeight, int totalWays) {
    if (currentHeight == height) return totalWays + 1;
    for (int i=1;i<=Math.min(maxSteps, height - currentHeight);i++) {
      totalWays = staircaseTraversalRec(height, maxSteps, currentHeight + i, totalWays);
    }
    return totalWays;
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM