code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

Nthfibonacci

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

public class NthFibonacci {

  static int func(int n) {
    if (n == 0) {
      return 0;
    }
    if (n == 1) {
      return 1;
    }
    return func(n - 1) + func(n - 2);
  }

  public static void main(String[] args) {
    int result = func(9);
    System.out.println(result);
  }
}

Created 2021-10-19T01:41:02+01:00, updated 2021-10-19T10:51:48+01:00 · History · Edit