当前位置:   article > 正文

力扣-1137.第N个泰波那契数_力扣疫情传播

力扣疫情传播

  1. class Solution(object):
  2. def tribonacci(self, n):
  3. """
  4. :type n: int
  5. :rtype: int
  6. """
  7. if n == 1 or n == 0:
  8. return n
  9. if n == 2:
  10. return 1
  11. dp_1 = 1
  12. dp_2 = 1
  13. dp_3 = 0
  14. for i in range(3, n + 1):
  15. res = dp_1 + dp_2 + dp_3
  16. dp_3 = dp_2
  17. dp_2 = dp_1
  18. dp_1 = res
  19. i = i + 1
  20. return dp_1
  21. if __name__ == '__main__':
  22. n = 25
  23. Sol = Solution()
  24. res = Solution.tribonacci(Sol, n)
  25. print(res)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/948558
推荐阅读
相关标签
  

闽ICP备14008679号