自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(79)
  • 资源 (1)
  • 收藏
  • 关注

原创 快速排序核心代码(递归实现+非递归实现)

今天做到lc75.颜色分类这道题,复习一下快速排序的写法,之前陪同学面试被问到非递归的快排写法,所以一起记录一下。

2022-07-05 16:22:14 357 1

原创 左值(Lvalues)与右值(Rvalues)

左值(Lvalues)与右值(Rvalues)定义Every C++ expression has a type, and belongs to a value category.左值右值都是表达式属性,该属性称为value category.在现代C++中,对于左值表达式,通过具体名字和引用来指定一个对象,非左值就是右值。左值表示程序中必须有一个特定的名字引用到这个值。An lvalue has an address that your program can access. Exam

2022-01-24 19:14:12 833

原创 二叉树本地调试范例

struct TreeNode { int val; TreeNode* left; TreeNode* right; TreeNode(int x): val(x), left(NULL), right(NULL) {}};class Solution {public: int count = 0; int pathSum(TreeNode* root, int sum) { if (root == NULL) return count; dfs(root, sum); p.

2022-01-24 18:48:34 296 1

原创 剑指Offer 19.正则表达式匹配

剑指Offer 19.正则表达式匹配示例 1:输入:s = “aa”p = “a”输出: false解释: “a” 无法匹配 “aa” 整个字符串。示例 2:输入:s = “aa”p = “a*”输出: true解释: 因为 ‘*’ 代表可以匹配零个或多个前面的那一个元素, 在这里前面的元素就是 ‘a’。因此,字符串 “aa” 可被视为 ‘a’ 重复了一次。示例 3:输入:s = “ab”p = “.*”输出: true解释: “.*” 表示可匹配零个或多个(

2022-01-19 16:26:02 341 1

原创 由vector的size()函数引发的越界问题

由vector的size()函数引发的越界问题在做剑指 Offer 04. 二维数组中的查找一题时,如下代码:class Solution {public: bool findNumberIn2DArray(vector<vector<int>>& matrix, int target) { int i = matrix.size() - 1, j = 0; while (i >= 0 && j <=

2022-01-16 09:55:20 884 1

原创 力扣刷题之排序

力扣刷题之排序 147.对链表进行插入排序148.排序链表147.对链表进行插入排序class Solution {public: ListNode* insertionSortList(ListNode* head) { if (head == nullptr) { return head; } ListNode* dummyHead = new ListNode(0); dummyHead->

2021-11-17 20:30:14 511 1

原创 力扣刷题之深度优先搜索

力扣刷题之深度优先搜索98.验证二叉搜索树99.恢复二叉搜索树113.路径总和II114.二叉树展开为链表116.填充每个节点的下一个右侧节点指针117.填充每个节点的下一个右侧节点指针II129.求根节点到叶节点数字之和199.二叉树的右视图98.验证二叉搜索树法一:递归class Solution {public: bool helper(TreeNode* root, long long lower, long long upper) { if (root == n

2021-11-10 17:15:22 757

原创 Linux网络编程(二)

Linux网络编程(二)Unix/Linux模型基本结构流和标准I/O库进程进程控制进程建立fork()exec()exec和fork的联用进程的终止exit()进程的同步wait()进程的属性进程标识符进程组标识符进程环境进程的有效标识符进程的优先级进程、进程组和会话的关系守护进程守护进程的启动守护进程的错误输出守护进程的建立步骤Unix/Linux模型基本结构三个层次:用户内核硬件Unix内核结构:内核主要成分:文件子系统进程控制子系统系统调用与库函数区别:系统调用

2021-10-27 16:42:52 651

原创 力扣刷题之哈希表

力扣刷题之哈希表133.克隆图138.复制带随机指针的链表146.LRU缓存机制(手写双向链表)202.快乐数133.克隆图法一:深度搜索class Solution {public: unordered_map<Node*, Node*> visited; Node* cloneGraph(Node* node) { if (node == nullptr) { return node; }

2021-10-27 09:09:13 174

原创 力扣刷题之动态规划

力扣刷题之动态规划241.为运算表达式设计优先级263.丑数264.丑数II313.超级丑数338.比特位计数241.为运算表达式设计优先级分治+递归class Solution {public: vector<int> diffWaysToCompute(string expression) { // 存储中间值 vector<int> count; for(int i = 0; i < expression

2021-10-25 17:13:49 118

原创 力扣刷题之字符串

力扣刷题之字符串6.Z字形变换8.字符串转换整数(atoi)12.整数转罗马数字6.Z字形变换class Solution {public: string convert(string s, int numRows) { if (numRows == 1) return s; vector<string> rows(min(numRows, int(s.size()))); // 防止s的长度小于行数 int curRow = 0; bool goingDown =

2021-10-21 09:38:18 362

原创 力扣刷题之数组(二)

力扣刷题之数组(二)200.岛屿数量204.计数质数209.长度最小的子数组215.数组中的第K个最大元素(经典!)220.存在重复元素III(经典)221.最大正方形229.求众数II238.除自身以外数组的乘积240.搜索二维矩阵II260.只出现一次的数字III剑指Offer II 080.含有k个元素的组合剑指Offer II 079.所有子集200.岛屿数量class Solution {private: void dfs(vector<vector<char>&

2021-10-17 09:45:22 98

原创 Linux网络编程基础

Linux网络编程基础第5章 Linux网络编程基础API5.1 socket地址API5.1.1 主机字节序和网络字节序5.1.2 通用socket地址5.1.3 专用socket地址5.1.4 IP地址转换函数5.2 创建socket5.3 命名socket5.4监听socket5.5 接受连接5.6 发起连接5.7 关闭连接5.8 数据读写5.8.1 TCP数据读写5.8.2 UDP数据读写5.8.3 通用数据读写函数5.10 地址信息函数5.12 网络信息API5.12.1 gethostbynam

2021-10-08 15:30:05 727

原创 力扣刷题之数组

力扣刷题之数组41.缺失的第一个正数42.接雨水54.螺旋矩阵56.合并区间57.插入区间59.螺旋矩阵II64.最小路径和73.矩阵置零74.搜索二维矩阵75.颜色分类79.单词搜索26.删除有序数组中的重复项80.删除有序数组中的重复项II41.缺失的第一个正数https://leetcode-cn.com/problems/first-missing-positive/solution/que-shi-de-di-yi-ge-zheng-shu-by-leetcode-solution/

2021-09-28 11:45:03 162

原创 剑指Offer 68-II.二叉树的最近公共祖先

class Solution {public: unordered_map<int, TreeNode*> fa; unordered_map<int, bool> vis; void dfs(TreeNode* root){ if (root->left != nullptr) { fa[root->left->val] = root; dfs(root->left..

2021-09-24 09:25:28 48

原创 剑指Offer 68-I.二叉搜索树的最近公共祖先

https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-zui-jin-gong-gong-zu-xian-lcof/solution/er-cha-sou-suo-shu-de-zui-jin-gong-gong-0wpw1/class Solution {public: vector<TreeNode*> getPath(TreeNode* root, TreeNode* target) { vector..

2021-09-23 11:54:01 62

原创 剑指Offer 64.求1+2+...+n

https://leetcode-cn.com/problems/qiu-12n-lcof/solution/qiu-12n-by-leetcode-solution/class Solution {public: int sumNums(int n) { n && (n += sumNums(n-1)); return n; }};

2021-09-23 11:28:51 55

原创 剑指Offer 63.股票的最大利润

class Solution {public: int maxProfit(vector<int>& prices) { int inf = 1e9; int minprice = inf, maxprofit = 0; for (int price: prices) { maxprofit = max(maxprofit, price - minprice); minprice .

2021-09-23 11:00:40 50

原创 剑指Offer 62.圆圈中最后剩下的数字

https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/solution/jian-zhi-offer-62-yuan-quan-zhong-zui-ho-dcow/本题是著名的 “约瑟夫环” 问题,可使用 动态规划 解决。class Solution {public: int lastRemaining(int n, int m) { int x = 0;..

2021-09-23 10:42:04 51

原创 剑指Offer 55-II.平衡二叉树

自顶向下的递归类似于二叉树前序遍历class Solution {public: int height(TreeNode* root) { if (root == NULL) { return 0; } else { return max(height(root->left), height(root->right)) + 1; } } bool isBalanced.

2021-09-23 10:03:53 47

原创 剑指Offer 61.扑克牌中的顺子

class Solution {public: bool isStraight(vector<int>& nums) { vector<int> map(14); //构建哈希集合 int minValue = INT_MAX, maxValue = INT_MIN; for(int n : nums) { if(map[n] >= 1) return ..

2021-09-23 09:25:20 47

原创 剑指Offer 67.把字符串转换成整数

class Solution {public: int strToInt(string str) { int ret = 0; // 转换后的数字 int flag = 1; // 标记正负号 int len = str.size(); if (len <= 0) return ret; // 临界条件 int index = 0; // 遍历字符串,寻找第一个不是空格的字符 w.

2021-09-23 08:44:22 50

原创 剑指Offer 60.n个骰子的点数

https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/solution/jian-zhi-offer-60-n-ge-tou-zi-de-dian-sh-z36d/class Solution {public: vector<double> twoSum(int n) { int dp[15][70]; memset(dp, 0, sizeof(dp));//初始化dp数组 ..

2021-09-22 20:53:37 39

原创 剑指Offer 66.构建乘积数组

整体思路:结果集中任何一个元素 = 其左边所有元素的乘积 * 其右边所有元素的乘积。一轮循环构建左边的乘积并保存在结果集中,二轮循环 构建右边乘积的过程,乘以左边的乘积,并将最终结果保存class Solution {public: vector<int> constructArr(vector<int>& a) { int len = a.size(); if (len == 0) return {}; // 判空 ..

2021-09-22 18:04:27 39

原创 剑指Offer 59-II.队列的最大值

class MaxQueue { int q[20000]; int begin = 0, end = 0;public: MaxQueue() { } int max_value() { int ans = -1; for (int i = begin; i != end; ++i) ans = max(ans, q[i]); return ans; } .

2021-09-22 17:25:56 37

原创 剑指Offer 65.不用加减乘除做加法

class Solution {public: int add(int a, int b) { while(b!=0){ int c=(unsigned int)(a&b)<<1;// c++不支持负值左移,需要强制转换为无符号数 a^=b; b=c; } return a; }};...

2021-09-14 09:35:27 38

原创 剑指Offer 49.丑数

https://leetcode-cn.com/problems/chou-shu-lcof/solution/chou-shu-by-leetcode-solution-0e5i/小根堆,注意小根堆的定义方式class Solution {public: int nthUglyNumber(int n) { vector<int> factors = {2, 3, 5}; unordered_set<long> seen;..

2021-09-13 22:16:40 86

原创 剑指Offer 54.二叉搜索树的第k大节点

//自己写的class Solution {public: int kthLargest(TreeNode* root, int k) { vector<int>r=inorder(root); return r[k-1]; } vector<int>res; vector<int> inorder(TreeNode*root){ if(root==NULL)retur.

2021-09-13 21:38:30 43

原创 剑指Offer 48.最长不含重复字符的子字符串

滑动窗口class Solution {public: int lengthOfLongestSubstring(string s) { int maxsub = 0, left = 0, pos = 0; vector<bool> used(256, false); while(pos < s.size()){ while(used[s[pos]]) used[s[left++]] = false..

2021-09-13 21:19:07 34

原创 剑指Offer 58-II.左旋转字符串

class Solution {public: string reverseLeftWords(string s, int n) { string res; res.append(s.substr(n,s.size()-n)); res.append(s.substr(0,n)); return res; }};

2021-09-13 20:38:30 59

原创 剑指Offer 58-I.翻转单词顺序

https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/solution/mian-shi-ti-58-i-fan-zhuan-dan-ci-shun-xu-shuang-z/class Solution {public: string reverseWords(string s) { string res; int n = s.size(); if(n == 0) r..

2021-09-13 20:22:57 39

原创 剑指Offer47.礼物的最大价值

class Solution { public int maxValue(vector<vector<int>>& grid) { int m = grid.size(), n = grid[0].size(); for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(i == 0 &&amp..

2021-09-13 20:00:44 41

原创 剑指Offer-46.把数字翻译成字符串

https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/solution/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-by-leetcode-sol/「滚动数组」优化动态规划的方法,这是一种非常常见的空间优化整型转换为字符串型class Solution {public: int translateNum(int num) { string src = t..

2021-09-13 19:42:33 40

原创 剑指Offer-57-II.和为s的连续正数序列

class Solution {public: vector<vector<int>> findContinuousSequence(int target) { vector<vector<int>> vec; vector<int> res; int sum = 0, limit = (target - 1) / 2; // (target - 1) / 2 等效于 target / ..

2021-09-10 22:01:16 43

原创 剑指Offer-45.把数组排成最小的数

https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/solution/mian-shi-ti-45-ba-shu-zu-pai-cheng-zui-xiao-de-s-4/class Solution {public: string minNumber(vector<int>& nums) { vector<string> strs; ...

2021-09-10 21:25:11 58

原创 剑指Offer-57.和为s的两个数

双指针class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { int i=0,j=nums.size()-1; while(i<j){ if(nums[i]+nums[j]>target){ j--; }else if(nums[i]+num..

2021-09-10 20:15:21 35

原创 剑指Offer-56-I、II.数组中数字出现的次数

https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/solution/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-by-leetcode/class Solution {public: vector<int> singleNumbers(vector<int>& nums) { int ret = 0;/...

2021-09-08 23:21:15 42

原创 剑指Offer 55-I.二叉树的深度

class Solution {public: int maxDepth(TreeNode* root) { if(!root){ return 0; } return max(maxDepth(root->left),maxDepth(root->right))+1; }};

2021-09-08 22:36:04 58

原创 剑指Offer-51.数组中的逆序对

考点:归并排序与逆序对息息相关考虑在归并排序的合并阶段统计「逆序对」数量,完成归并排序时,也随之完成所有逆序对的统计。https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/solution/jian-zhi-offer-51-shu-zu-zhong-de-ni-xu-pvn2h/class Solution {public: int mergeSort(vector<int>& num..

2021-09-08 22:16:58 51

原创 剑指Offer-34.二叉树中和为某一值的路径

考点:回溯class Solution {public: vector<vector<int>>ret; vector<int>path; void dfs(TreeNode* root,int target){ if(root==nullptr){ return; } path.emplace_back(root->val); target-=..

2021-09-08 20:42:46 50

STL源码剖析侯捷课件

STL源码剖析侯捷课件

2021-07-21

空空如也

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

TA关注的人

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