自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(12)
  • 收藏
  • 关注

原创 程序员面试金典

面试题 01.08. 零矩阵原题链接思路:先标记后置0class Solution {public: void setZeroes(vector<vector<int>>& matrix) { int rows = matrix.size(); if (rows == 0) return; int cols = matrix[0].size(); vector<int>r(rows,1

2020-05-25 22:43:24 365

原创 Leetcode刷题

Leetcode5. 最长回文子串原题链接class Solution {public: string longestPalindrome(string s) { int len = s.size(); string ans = ""; vector<vector<int>> dp(len, vector<int>(len,0)); for (int l = 0;l < len;l++)

2020-05-21 21:16:54 161

原创 二叉树的先序,中序,后序遍历非递归实现

二叉树的先序非递归实现思路:用栈模拟先序过程,先序是先根节点,后左节点,后右节点void preOrderWithoutRecusive(TreeNode* root){ if (root == nullptr) return; stack<TreeNode*>sta; TreeNode* tmp = root; while (!sta.empty() || tmp) { if (tmp) { cout << tmp->val <<

2020-05-20 23:12:54 525 1

原创 剑指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 138

原创 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 177

原创 剑指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-&gt

2020-05-15 20:16:43 139

原创 剑指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 138

原创 剑指offer:面试题65. 不用加减乘除做加法

面试题65. 不用加减乘除做加法原题链接思路 :与运算计算进位 异或运算计算非进位和 不断循环直至进位为0class 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 189

原创 LeetCode15. 三数之和

LeetCode15. 三数之和原题链接思路 排序加双指针注意点 去重和剪枝加速class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> ans; sort(nums.begin(),nums.end(),[](int a,int b){return a <

2020-05-14 14:28:35 142

原创 LeetCode 136. 只出现一次的数字

LeetCode 136. 只出现一次的数字题目链接思路:位运算求解 。0和任何数的异或都是任何数本身,相同数的异或等于0class Solution {public: int singleNumber(vector<int>& nums) { int ans = 0; for (auto n : nums){ ans = ans ^ n; } return ans; }};

2020-05-14 14:04:08 150

原创 LeetCode 146. LRU缓存机制

LeetCode 146. LRU缓存机制原题地址思路:双向链表(STL中的list)和哈希表,其中双向链表保存数据,哈希表作为维护的映射工具注意点:更新cache的双向链表时记得同步更新哈希表中数据class LRUCache {public: unordered_map<int, list<pair<int, int>>::iterator>ma; list<pair<int, int>>cache; int capa; in

2020-05-14 12:04:29 156

原创 快排算法,优化,非递归实现以及链表的快排

快速排序算法void QuickSort(vector<int>&arr, int left, int right){ if (left >= right) return; int i = left; int j = right; while (i < j)//左右指针相向遍历交换 { while (arr[j] > arr[left] && i < j)//最左侧数作为基准数 { j-

2020-05-13 21:13:44 196

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除