自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 50-Pow(x, n)

class Solution {public: double myPow(double x, long long n) { if (n == 0 ) return 1; if (n < 0) return 1 / myPow(x, -n); // 如果n是奇数 if (n % 2) { return x * myPow(x, n - 1); } return myPow(.

2020-08-31 22:50:32 64

原创 76-最小覆盖子串

class Solution {public: string minWindow(string s, string t) { if(s.size() < t.size()) return ""; unordered_map<char, int>need; //目标查询的字符以及数量 for (int i = 0; i < t.size(); i++) { need[t[i]]++; }.

2020-08-30 23:33:10 197

原创 剑指offer49-丑数

class Solution {public: int nthUglyNumber(int n) { if (n < 6) return n; // 搜索起点 int start2 = 1, start3 =1, start5 = 1; vector<int>dp(n + 1, 0); for (int i = 1; i <= 6; i++) { dp[i] = i...

2020-08-28 10:08:40 65

原创 106-从中序与后序遍历序列构造二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* buildTree(vector<.

2020-08-27 10:43:26 76

原创 105-从前序和中序遍历序列构造二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* buildTree(vector<.

2020-08-27 10:41:02 84

原创 多线程打印循环打印ABC、多线程打印奇偶数

多线程打印循环打印ABC(10次)#include <iostream>#include <thread>#include <condition_variable>std::mutex mtx;std::condition_variable cv;int ready = 0;void PrintString_1(){ std::unique_lock<std::mutex> lk(mtx); int cnt =

2020-08-26 18:35:39 160

原创 iOS中Block循环引用的问题

https://www.cnblogs.com/wanli-leon/p/9723416.html

2020-08-26 17:08:58 54

原创 300-最长上升子序列

class Solution {public: int lengthOfLIS(vector<int>& nums) { if (nums.size() < 1) { return 0; } int maxLength = 1; vector<int>dp(nums.size(), 1); for (int i = 1; i < nums.size(.

2020-08-26 13:42:24 74

原创 222-完全二叉树的节点个数

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int countNodes(TreeNode* root).

2020-08-24 11:45:23 121

原创 109-有序链表转换二叉搜索树

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next.

2020-08-23 11:08:00 94 1

原创 56-合并区间

1、对 vector<vector> 排序,需要按照先比较区间开始,如果相同再比较区间结束, 使用默认的排序规则即可2、使用双指针,左边指针指向当前区间的开始3、使用一个变量来记录连续的范围 t4、右指针开始往后寻找,如果后续的区间的开始值比 t 还小,说明重复了,可以归并到一起5、此时更新更大的结束值到 t6、直到区间断开,将 t 作为区间结束,存储到答案里7、然后移动左指针,跳过中间已经合并的区间class Solution {public: vector&l.

2020-08-23 09:39:09 76

原创 面试题01.04-回文排列

class Solution {public: bool canPermutePalindrome(string s) { vector<int>arr(128, 0); for (int i = 0; i < s.size(); i++) { int index = s[i] - 0; arr[index]++; } // 字符个数为奇数的个数 in.

2020-08-22 11:36:49 129

原创 679-24点游戏

class Solution {public: bool judgePoint24(vector<int>& nums) { vector<double>arr(nums.begin(), nums.end()); return helper(arr); } bool helper(vector<double>&arr) { int length = arr.size(); .

2020-08-22 10:32:17 232

原创 127-单词接龙

class Solution {public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { unordered_set<string> wordDict(wordList.begin(), wordList.end()); if (wordDict.find(endWord) == wordDict.end()) ret.

2020-08-21 11:30:06 86

原创 198-打家劫舍(动态规划)

class Solution {public: int rob(vector<int>& nums) { int length = nums.size(); if (length <= 1) { if (length == 0) { return 0; } else { return nums[0]; .

2020-08-20 10:23:16 86

原创 152-乘积最大子数组

class Solution {public: int maxProduct(vector<int>& nums) { int a = 1, maxNum = nums[0]; for (int &num : nums) { a = a * num; if (maxNum < a) { maxNum = a; } .

2020-08-20 10:07:32 71

原创 414-第三大的数

class Solution {public: int thirdMax(vector<int>& nums) { if (nums.size() == 1) { return nums[0]; } if (nums.size() == 2) { return max(nums[0], nums[1]); } long n1 = LONG_MIN;.

2020-08-18 15:00:33 98

原创 1143-最长公共子序列的长度和最长公共子序列

/* * 最长公共子序列-动态规划 * dp[i][j]表示str1前i子串和str2前j子串的最长公共子序列长度 * dp[i][j]取决于dp[i-1][j], dp[i][j-1], dp[i-1][j-1] * 时间复杂度O(MN) 空间复杂度O(MN) */class Solution {public: // 最长公共子序列长度 int longestCommonSubsequence(string text1, string text2) { if.

2020-08-18 14:15:43 193

原创 42-接雨水(单调递减栈)

class Solution {public: int trap(vector<int>& height) { if (height.size() <= 2) { return 0; } int maxIndex = 0, maxNum = height[0]; for (int i = 1; i < height.size(); i++) { if (.

2020-08-16 11:58:49 164

原创 200-岛屿的数量

class Solution {public: int numIslands(vector<vector<char>>& grid) { int ans = 0; for (int i = 0; i < grid.size(); i++) { for (int j = 0; j < grid[0].size(); j++) { if (grid[i][j] == ..

2020-08-15 09:27:55 98

原创 负载均衡算法

https://www.cnblogs.com/CodeBear/archive/2019/03/11/10508880.html

2020-08-14 00:44:32 90

原创 四种限流算法

https://www.cnblogs.com/linjiqin/p/9707713.html

2020-08-13 22:44:58 145

原创 470-用Rand7()实现Rand10()

// The rand7() API is already defined for you.// int rand7();// @return a random integer in the range 1 to 7class Solution {public: int rand10() { int x = ~(1 << 31); // max int // 这里40是10的倍数中小于且最接近与 7 * 7的数 while (x.

2020-08-13 15:02:05 214

原创 328-奇偶链表(按链表结点编号的奇偶性分割链表)

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next.

2020-08-13 14:51:42 186

原创 leetcode41-缺失的第一个正数

class Solution {public: int firstMissingPositive(vector<int>& nums) { int i = 0, n = nums.size(); while (i < n) { if (nums[i] > 0 && nums[i] <= n && nums[nums[i] - 1] != nums[i]) { .

2020-08-13 10:26:42 81

原创 HTTP3.0

https://www.cnblogs.com/chenjinxinlove/p/10104854.html

2020-08-12 21:43:31 228

原创 猿辅导面试算法题

53-二叉树搜索树的最小绝对差/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int getMinimum

2020-08-09 22:29:52 836

原创 530-二叉搜索树的最小绝对差

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int getMinimumDifference(TreeN.

2020-08-09 20:38:05 61

原创 除了IPV6外还有什么方法能解决IPV4不足的情况

动态NAT转化https://www.cnblogs.com/fonxian/p/11265914.html

2020-08-09 18:12:12 250

原创 C++中基类的析构函数不是虚函数,会带来什么问题?

https://www.cnblogs.com/qkqBeer/articles/11154898.html

2020-08-09 17:01:10 578

原创 线程池原理

https://www.cnblogs.com/yanggb/p/10629387.html

2020-08-09 15:01:40 63

原创 分布式系统中的session同步

分布式系统中的session同步https://www.cnblogs.com/yixiao21/p/8423850.html

2020-08-09 11:02:46 108

原创 浅谈HTTP中GET、POST用法以及它们的区别

https://www.cnblogs.com/williamjie/p/9099940.htmlhttps://blog.csdn.net/ever_siyan/article/details/87935455

2020-08-08 22:15:57 65

原创 聚簇索引和非聚簇索引总结

什么是聚合索引(clustered index) / 什么是非聚合索引(nonclustered index)?聚合索引和非聚合索引有什么区别?深入浅出理解索引结构https://www.cnblogs.com/sunliyuan/p/5826419.html聚簇索引的优势和劣势https://www.jianshu.com/p/fa8192853184一: 深入浅出理解索引结构把索引理解为一种特殊的目录。微软的SQL SERVER提供了两种索引:聚集索引(clustered index,.

2020-08-08 20:58:01 209 1

原创 238-除自身以外数组的乘积

class Solution {public: vector<int> productExceptSelf(vector<int>& nums) { int length = nums.size(); int leftCur = 1, rightCur = 1; vector<int>leftArr; for (int i = 0; i < length; i++) { .

2020-08-08 11:50:22 67

原创 剑指offer24-反转链表

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* reverseList(ListNode* head) { if (head == NULL) r.

2020-08-06 11:20:40 86

原创 235-二叉搜索树的最近公共祖先

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* lowestCommonAncest..

2020-08-06 10:59:57 70

原创 231-2的幂

解法一:class Solution {public: bool isPowerOfTwo(int n) { if (n < 1) return false; if (n == 1) return true; while (n % 2 == 0) { n /= 2; if (n == 2 || n == 1) { return true; .

2020-08-06 10:52:11 67

原创 230-二叉搜索树中第K小的元素

递归版:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) .

2020-08-06 10:39:54 203

原创 1115-交替打印FooBar和交替ABC

class FooBar {private: int n; mutex mtx; condition_variable cv; int flag;public: FooBar(int n) { this->n = n; flag = 0; } void foo(function<void()> printFoo) { for (int i = 0; i &lt.

2020-08-05 09:57:51 143

空空如也

空空如也

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

TA关注的人

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