1. 变态跳台阶

     Fib(n) = Fib(n-1)+Fib(n-2)+Fib(n-3)+..........+Fib(n-n)

           =Fib(0)+Fib(1)+Fib(2)+.......+Fib(n-2)+Fib(n-1)
而Fib(n-1)=Fib(0)+Fib(1)+Fib(2)+.......+Fib(n-2)
两式相减得:Fib(n) - Fib(n-1) = Fib(n-1) =====》 Fib(n) = 2*Fib(n-1)

 剑指offer相关问题

ref

 

2. 二叉搜索树的后序遍历序列

 1 bool VerifySquenceOfBST(vector<int> sequence) {
 2     if (sequence.empty()) {
 3         return false;
 4     }
 5     return verifyBST(sequence, 0, sequence.size() - 1);
 6 }
 7 
 8 bool verifyBST(vector<int>& sequence, int start, int end) {
 9     if (start >= end) {
10         return true;
11     }
12     int rootVal = sequence[end];
13     int i;
14     for (i = start; i < end; i++) {
15         if (sequence[i] > rootVal) {
16             break;
17         }
18     }
19     int index = i;
20     for (; i < end; i++) {
21         if (sequence[i] < rootVal) {    
22             return false;
23         }
24     }
25     return verifyBST(sequence, start, index - 1) && verifyBST(sequence, index, end - 1);
26 }
View Code

相关文章:

  • 2021-12-29
  • 2021-08-21
猜你喜欢
  • 2021-05-27
  • 2022-12-23
  • 2021-08-26
  • 2021-09-02
  • 2021-06-15
  • 2021-08-17
相关资源
相似解决方案