摘要:
面试题 26. 树的子结构 阅读全文
摘要:
面试题 18. 删除链表的节点 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * Li 阅读全文
摘要:
面试题 16. 数值的整数次方 class Solution { public: double myPow(double x, int n) { // 快速幂算法通过将底数平方和指数减半的方式,减少了计算时间,从而将复杂度降低到 O(logn) // 最小的负数的绝对值 比 最大的正数 更大,所以用 阅读全文
摘要:
面试题 14- I. 剪绳子 #include <iostream> #include <vector> using namespace std; class Solution { public: static int cuttingBamboo(const int bamboo_len) { ve 阅读全文
摘要:
1. static和auto的相似之处 // 只不过这里auto默认省略不写 auto int a=10; auto string str="this is a string"; static int a=10; static string str="this is a string"; 区别是: 阅读全文
摘要:
面试题 12. 矩阵中的路径 #include <iostream> #include <vector> #include <functional> using namespace std; class Solution { public: bool exist(vector<vector<char 阅读全文
摘要:
1. 前中后序递归遍历 // 前序遍历 class Solution { public: void traversal(TreeNode* cur, vector<int>& vec) { if (cur == NULL) return; vec.push_back(cur->val); // 中 阅读全文
摘要:
1. DFS深度优先算法 /* - 深度优先算法 DFS 从起始节点出发,沿着一条路径尽可能深入地访问每个节点,直到无法继续时再回退,寻找未访问的节点。 - 使用递归实现。 */ #include <iostream> #include <vector> using namespace std; v 阅读全文
摘要:
一、什么是左值、右值? 专业的说法: 左值是指表达式结束后依然存在的持久化对象; 右值是指表达式结束后就不再存在的临时对象。 通俗的说法:有名字的对象都是左值,右值没有名字。 区分左右值得便捷方法:看能不能对表达式取地址,如果能,则为左值,否则为右值 Tips: C++11把右值分为纯右值和将亡值。 阅读全文
摘要:
面试题 07. 重建二叉树 前中序构建 要根据二叉树的前序遍历和中序遍历结果来构建二叉树,我们可以利用以下性质: 前序遍历的第一个元素总是当前树的根节点。 中序遍历中,根节点将二叉树分为左子树和右子树。 思路 根据前序遍历的第一个元素确定根节点。 在中序遍历中找到根节点位置,这样可以确定左子树和右子 阅读全文