Loading

摘要: 思路 方法一:递归 以下代码改成c++中string的写法,提交到C++中会超时,可能string比指针更慢吧。 以下C语言代码参考《剑指offer(第2版)》书中的代码,可以在leetcode中提交通过。 这种递归方法效率比较低下。 1 bool matchCore(const char* str 阅读全文
posted @ 2020-11-16 20:37 拾月凄辰 阅读(63) 评论(0) 推荐(0) 编辑
摘要: 思路 转载自: 面试题68 - II. 二叉树的最近公共祖先(后序遍历 DFS ,清晰图解) 方法:后序遍历 (自底向上) 阅读全文
posted @ 2020-11-16 18:01 拾月凄辰 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 思路 方法一:迭代 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) 阅读全文
posted @ 2020-11-16 17:20 拾月凄辰 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 思路 方法:模拟 本题难点在于怎么判断数字是否超过int的范围,这里有两个方法解决: (1) 使用long long直接判断 1 class Solution { 2 public: 3 int strToInt(string str) { 4 if(str.empty()) 5 return 0; 阅读全文
posted @ 2020-11-16 12:12 拾月凄辰 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 思路 方法:对称遍历 1 class Solution { 2 public: 3 vector<int> constructArr(vector<int>& a) { 4 if(a.empty()) 5 return vector<int>(); 6 7 vector<int> b(a.size( 阅读全文
posted @ 2020-11-16 10:57 拾月凄辰 阅读(93) 评论(0) 推荐(0) 编辑