Skip to content

Commit b7ae51a

Browse files
committed
edit solution of 509
1 parent 28268cc commit b7ae51a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/problems/509.fibonacci-number.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@
6060
## @lc code=start
6161
using LeetCode
6262

63-
function fib(n::Int)
64-
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040][n]
63+
function fib(n::Int)::Int
64+
n <= 1 && return n
65+
pre, cur = 0, 1
66+
for _ in 2:n
67+
pre, cur = cur, pre + cur
68+
end
69+
return cur
6570
end
71+
6672
## @lc code=end

test/problems/509.fibonacci-number.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@testset "509.fibonacci-number.jl" begin
2-
@test fib(5) == 5
2+
@test fib.(0:10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
33
end

0 commit comments

Comments
 (0)