剑指offer
weixin_42683621
这个作者很懒,什么都没留下…
展开
-
剑指offer刷题
面试题19. 正则表达式匹配 原题链接 动态规划 class Solution { public: bool isMatch(string s, string p) { int len1 = s.size(); int len2 = p.size(); vector<vector<bool>>dp(len1 + 1, vector<bool>(len2 + 1, 0)); //边界处理 dp[0][0] = true; for (int i =原创 2020-05-17 21:28:40 · 96 阅读 · 0 评论 -
LeetCode刷题
LeetCode 122. 买卖股票的最佳时机 II 原题链接 贪心算法 class Solution { public: int maxProfit(vector<int>& prices) { int len = prices.size(); int maxPro = 0; for (int i = 1;i < len;i++){ if (prices[i] > prices[i-1]){原创 2020-05-16 22:11:38 · 144 阅读 · 0 评论 -
剑指offer 面试题54. 二叉搜索树的第k大节点
面试题54. 二叉搜索树的第k大节点 修改的中序遍历 class Solution { public: int ans; int kthLargest(TreeNode* root, int k) { dfs(root, k); return ans; } void dfs(TreeNode* root, int &k){ if (root == nullptr) return; dfs(root->原创 2020-05-15 20:16:43 · 97 阅读 · 0 评论 -
剑指offer 面试题55 - II. 平衡二叉树
面试题55 - II. 平衡二叉树 原题链接 后序遍历计算高度时判断高度差 class Solution { public: bool sign=true; bool isBalanced(TreeNode* root) { getDepth(root); return sign; } int getDepth(TreeNode* root){ if (root == nullptr) return 0原创 2020-05-15 20:14:02 · 100 阅读 · 0 评论 -
剑指offer:面试题65. 不用加减乘除做加法
面试题65. 不用加减乘除做加法 原题链接 思路 :与运算计算进位 异或运算计算非进位和 不断循环直至进位为0 class Solution { public: int add(int a, int b) { while (b != 0) { int c = ((unsigned int)(a & b) << 1); // 计算进位. 先保留同为1的位,都为1的位要向左进位,因此左移1位 c++不支持负值左移 a原创 2020-05-15 20:10:29 · 141 阅读 · 0 评论