To the Top
File:  root - text - article - 2020 - 01 - nth-fibonacci-number.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 250 Views, 20382 Search Bots | 97 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Apple:

The Fibonacci sequence is the integer sequence defined by the recurrence relation: F(n) = F(n-1) + F(n-2), where F(0) = 0 and F(1) = 1. In other words, the nth Fibonacci number is the sum of the prior two Fibonacci numbers. Below are the first few values of the sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...

Given a number n, print the n-th Fibonacci Number.
Examples:
Input: n = 3
Output: 2

Input: n = 7
Output: 13
Here's a starting point:


class Solution():
def fibonacci(self, n):
# fill this in.

n = 9
print(Solution().fibonacci(n))
# 34
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 250 Views, 20382 Search Bots | 97 Words Subscribe to Feed Burner

Related Articles

  1. [Daily Problem] Course Prerequisites
  2. Daily Interview Problem: Reverse Words in a String
  3. Algorithm Interview: Shifted String
  4. Floor and Ceiling of a Binary Search Tree
  5. Daily Interview Problem: Find the k-th Largest Element in a List
  6. Algorithm Interview: Convert Roman Numerals to Decimal
  7. Daily Interview Problem: Largest Product of 3 Elements I
  8. Algorithm Interview: Longest Consecutive Sequence
  9. 56 Bytes
  10. CVE-2015-8874 - cPanel EasyApache Vulnerabilities

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">