Problem: Write a function to calculate fibonacci number in constant space complexity.
(defn fib [n]
(loop [a 0
b 1
i n]
(if (= 0 i)
a
(recur b (+ a b) (dec i)))))
1 minute read
Problem: Write a function to calculate fibonacci number in constant space complexity.
(defn fib [n]
(loop [a 0
b 1
i n]
(if (= 0 i)
a
(recur b (+ a b) (dec i)))))
Thinker · Writer · Coder · Painter
Welcome to my personal website. In here, I talk about programming in general and other cool stuff. Stay tuned!
© Guowei Lv.
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Email