翻转链表

(栈)

#include <stack>
//
class Solution {
public:
    vector<int> printListFromTailToHead(ListNode* head) {
        vector<int> res;
        stack<int> s;
        while(head != NULL){
            s.push(head->val);
            head = head->next;
        }
        while(!s.empty()){
            res.push_back(s.top());
            s.pop();
        }
        return res;
    }
};

重建二叉树

动态规划

int Fibonacci(int n) {
        // write code here
        int a = 1, b = 1, c = 1;
        for(int i = 3; i <= n; i ++){
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }
//从子问题开始解答 递归是从顶部开始 动态规划是从底下开始
int Fibonacci(int n) {
        // write code here
        if(n == 0){
            return 0;
        }
        if(n == 1){
            return 1;
        }
        int res = 0;
        int a = 0, b = 1;
        for(int i = 2; i <= n; i++){
            res = a + b;
            a = b;
            b = res;
        }
        return res;
    }

矩阵中的路径

二进制中1的个数

链表删除指定元素