![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode刷题
懒·洋·洋·
这个作者很懒,什么都没留下…
展开
-
树相关知识
树的结构定义 /** Definition for a binary tree node.*/ * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; 二叉树 二叉树的四种遍历:优秀解释 1)前序遍历 //法一:递归法 class Solution { p.原创 2020-08-30 16:36:26 · 143 阅读 · 0 评论 -
回溯法相关题目
回溯法(back tracking) 用回溯法解问题时,应明确定义问题的解空间。问题的解空间至少包含问题的一个(最优)解。 22.括号生成:medium class Solution { public: void backtrack(vector<string>& res, string s, int open, int close, int n){ //剪枝操作 if (open > n || close > n ||原创 2020-08-29 22:02:52 · 196 阅读 · 0 评论 -
递归
递归 LeetCode递归题目 合并两个有序链表:easy class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if (l1 == NULL) return l2; if (l2 == NULL) return l1; if (l1->val <= l2->val){ l1->原创 2020-08-28 09:01:39 · 70 阅读 · 0 评论 -
LeetCode题目
链表操作 遇到链表问题先在纸上画出结构 LeetCode原题:复杂链表的复制 解题思路一 使用哈希表将新旧链表一一对应; 根据原链表的next和random指针来构建新链表的next和random指针 class Solution { public: Node* copyRandomList(Node* head) { if (head == NULL) return NULL; unordered_map<Node*, Node*> mp;原创 2020-08-27 20:02:46 · 95 阅读 · 0 评论