Victor215
V2EX  ›  问与答

这里有两段好玩的代码(鸡和蛋的问题),哪个更好?

  •  
  •   Victor215 · Jan 27, 2018 · 2555 views
    This topic created in 3054 days ago, the information mentioned may be changed or developed.

    第一段代码:

    第二段代码:

    问题来了,哪个更好?什么情况下该用哪种?

    3 replies    2018-01-27 18:27:01 +08:00
    nutting
        1
    nutting  
       Jan 27, 2018 via Android
    stackoverflow?
    Victor215
        2
    Victor215  
    OP
       Jan 27, 2018
    最新的 chrome 下试了,发现第一种会爆栈,第二种不会,但是第二种最终会因为内存满了而爆掉。
    Kilerd
        3
    Kilerd  
       Jan 27, 2018
    @Victor215 第二种是因为尾递归优化解决了栈的问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3128 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 13:02 · PVG 21:02 · LAX 06:02 · JFK 09:02
    ♥ Do have faith in what you're doing.