0501-0510

501. Find Mode in Binary Search Tree $\star$

502. IPO $\star\star\star$

503. Next Greater Element II $\star\star$

504. Base 7 $\star$

505. The Maze II $\star\star$

506. Relative Ranks $\star$

507. Perfect Number $\star$

508. Most Frequent Subtree Sum $\star\star$

509. Fibonacci Number $\star$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution {
 public:
  int fib(int N) {
    if (N < 2) return N;

    int dp[] = {0, 0, 1};

    for (int i = 2; i <= N; ++i) {
      dp[0] = dp[1];
      dp[1] = dp[2];
      dp[2] = dp[0] + dp[1];
    }

    return dp[2];
  }
};

510. Inorder Successor in BST II $\star\star$