- 博客(20)
- 收藏
- 关注
原创 信号量的实现和使用
#include#include#include<condition_variable>#include#includeusing namespace std;class Semaphore{public:explicit Semaphore(unsigned int count);~Semaphore();public:void wait();void si...
2019-09-29 00:30:47 224
原创 [LeetCode] 905. Sort Array By Parity 按奇偶排序数组
前后指针操作即可。#include#includeusing namespace std;void SortArrayByParity(vector &vec){int left = 0;int right = vec.size() - 1;while (left < right){while (left < right && vec[lef...
2019-09-27 00:01:16 167
原创 C++11信号量
信号量我感觉可以实现线程之间传递和唤醒。很有意思的一种线程实现和线程同步。#include#include#include#include<condition_variable>using namespace std;class semaphone{public:semaphone(unsigned int count) :count(count) {}void w...
2019-09-24 23:13:06 498
原创 [LeetCode] Valid Palindrome 验证回文字符串
#include#includeusing namespace std;bool isZimu(char ch){if (ch >= ‘a’ && ch <= ‘z’ || ch >= ‘A’ && ch <= ‘Z’){return true;}else{return false;}}bool ValidPali...
2019-09-23 23:14:18 88
原创 [LeetCode] 252. Meeting Rooms 会议室
不是很难#include#include #includeusing namespace std;bool MeetingRooms(vector<std::pair<int, int>> &vec){sort(vec.begin(), vec.end(), [](std::pair<int, int> x, std::pair<in...
2019-09-20 23:59:48 190
原创 [LeetCode] 209. Minimum Size Subarray Sum 最短子数组之和
左右指针的想法用的好多啊#include#includeusing namespace std;int maxt(int a, int b){if (a > b){return a;}return b;}int mint(int a, int b){if (a < b){return a;}return b;}int MinimumSize...
2019-09-19 23:10:16 89
原创 [LeetCode] 137. Single Number II 单独的数字之二
1.位运算很巧妙的应用啊。#include#includeusing namespace std;int SingleNumberII(vector &vec){int res = 0;for (int i = 0; i < 32; i++){int sum = 0;for (int j = 0; j < vec.size(); j++){sum += ...
2019-09-18 23:32:51 129
原创 [LeetCode] 222. Count Complete Tree Nodes 求完全二叉树的节点个数
需要对于完全二叉树和满二叉树的概念和性质很熟悉#include#include#includeusing namespace std;struct TreeNode{int val;TreeNode lChild;TreeNode rChild;TreeNode(int val, TreeNodel = nullptr, TreeNoder = nullptr){t...
2019-09-17 22:44:01 88
原创 c语言结构体的比较
只判断是否相等,不比较大小有时候我们需要知道比较结构体的某一部分,以便做进一步处理。这就需要我们在比较的时候做一些结构体的地址的偏移和比较。我们通过比较test的fileds的是否相等,来进行下一步操作。#include<stdio.h>struct fileds{int a;int b;int c;};struct data{int user;int mask...
2019-09-16 22:28:28 6802
原创 [LeetCode] Trapping Rain Water 收集雨水
能收集雨水的地方肯定是两边都比他高的地方#include#includeusing namespace std;int maxt(int a, int b){if (a > b){return a;}return b;}int mint(int a, int b){if (a < b){return a;}return b;}int Trappi...
2019-09-15 21:36:13 62
原创 [LeetCode] Trapping Rain Water 收集雨水
好难的一道题目啊,不看图片不知道什么意思#include#includeusing namespace std;int maxt(int a, int b){if (a > b){return a;}return b;}int mint(int a, int b){if (a < b){return a;}return b;}int Tr...
2019-09-14 23:27:56 75
原创 159. Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
#include#include<unordered_map>#includeusing namespace std;int maxt(int a, int b){if (a > b){return a;}return b;}int LongestSubstringTwoDistinctCharacters(string str){int res = ...
2019-09-14 00:22:59 68
原创 [LeetCode] Strobogrammatic Number 对称数
不是很难的一道题目#include#includeusing namespace std;bool StrobogrammaticNumber(string str){int n = str.size() - 1;int i = 0;while (i < n){if (str[i] == str[n]){if (str[i] != ‘1’ && st...
2019-09-12 23:45:00 84
原创 235. Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点
按照二叉树的性质遍历即可#includeusing namespace std;struct TreeNode{int val;TreeNode lChild;TreeNode rChild;TreeNode(int val, TreeNodel = nullptr, TreeNoder = nullptr){this->val = val;this->l...
2019-09-11 23:19:05 73
原创 [LeetCode] 72. Edit Distance 编辑距离
#include#includeusing namespace std;int minT(int a, int b){if (a < b){return a;}return b;}int EditDistanceT(string word1, int i,int lenn, string word2, int j,int lenm){if (i == lenn){...
2019-09-10 22:41:10 95
原创 [LeetCode] Binary Tree Right Side View 二叉树的右侧视图
树的层次遍历的思路来解决#include#include#includeusing namespace std;struct TreeNode{int val;TreeNode lChild;TreeNode rChild;TreeNode(int val, TreeNodel = nullptr, TreeNoder = nullptr){this->val...
2019-09-09 22:47:46 54
原创 非递归实现二叉树的后序遍历
#include#includeusing namespace std;struct TreeNode{int val;TreeNode lChild;TreeNode rChild;TreeNode(int val, TreeNodel = nullptr, TreeNoder = nullptr){this->val = val;this->lChild ...
2019-09-07 23:56:44 83
原创 很有意思的一段代码
#include<stdio.h>typedef int(*func)(int, int);int minT(int a, int b){return a < b ? a : b;}int maxT(int a, int b){return a > b ? a : b;}int sum(int a, int b){return a + b;}s...
2019-09-05 22:41:09 234
原创 [LeetCode] 214. Shortest Palindrome 最短回文串
#include#includeusing namespace std;string ShortestPalindrome(string str){string t = str;reverse(t.begin(), t.end());int n = t.size(),i=0;for (i = n; i >= 0; i–){if (str.substr(0, i) == ...
2019-09-03 22:57:52 139
原创 [LeetCode] Binary Tree Postorder Traversal 二叉树的后序遍历
二叉树的后序遍历的非递归实现(肯定要用栈)先序遍历顺序root->left->right后续遍历顺序left->right->root我们在先序遍历的的非递归实现的时候变为root->right->left,然后在翻转即可或者插入的时候做相关的操作也可以。#include#include#includeusing namespace...
2019-09-01 00:08:55 76
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人