- 博客(19)
- 收藏
- 关注
原创 LeetCode每日一题_21_05_02(554. 员工的重要性)
554. 砖墙LeetCode每日一题 2021/05/02class Solution {public: int leastBricks(vector<vector<int>> &wall) { unordered_map<int, int> mp; int ans = 0; for(auto & w : wall){ int sum = 0;
2021-05-02 09:08:44
121
原创 LeetCode每日一题_21_04_30(137. 只出现一次的数字 II)
137. 只出现一次的数字 IILeetCode每日一题 2021/4/30//解法1:记录位数class Solution{public: int singleNumber(vector<int> &nums){ vector<int> bits(32, 0); for(int &num : nums){ for(int i = 0; i < 32; i++){ if(num & (1 << i)) bi
2021-04-30 15:07:39
122
1
原创 LeetCode每日一题_21_04_29(403. 青蛙过河)
403. 青蛙过河LeetCode每日一题 2021/4/29//DFSclass Solution{public: unordered_map<int, unordered_set<int>> visited; unordered_set<int> stone_pos; int done; bool dfs(int pre_pos, int speed){ int cur_pos = pre_pos + speed; if(speed <
2021-04-29 10:04:04
111
原创 LeetCode每日一题_21_04_28(633. 平方数之和)
633. 平方数之和LeetCode每日一题 2021/4/27//双指针class Solution{public: bool judgeSquareSum(int c){ long i = 0, j = sqrt(c); while(i <= j){ if(i * i + j * j < c) i++; else if(i * i + j * j > c) j--; else return true; } return false; }
2021-04-28 07:58:36
103
原创 LeetCode每日一题_21_04_27(938. 二叉搜索树的范围和)
938. 二叉搜索树的范围和LeetCode每日一题 2021/4/27//解法1: DFSclass Solution{public: int rangeSumBST(TreeNode *root, int low, int high){ if(root == nullptr) return 0; if(root -> val < low){ return rangeSumBST(root -> right, low, high); } if(root
2021-04-27 08:59:03
100
原创 LeetCode每日一题_21_04_26(1011. 在D天内送达包裹的能力)
1011. 在 D 天内送达包裹的能力LeetCode每日一题 2021/4/26//解法1class Solution{public: int shipWithinDays(vector<int> &weights, int D){ int left = *max_element(weights.begin(), weights.end()); int right = accumulate(weights.begin(), weights.end(), 0);
2021-04-26 09:50:35
90
原创 LeetCode每日一题_21_04_25(897. 递增顺序搜索树)
897. 递增顺序搜索树LeetCode每日一题 2021/4/25//解法1class Solution{private: TreeNode *resNode;public: void inOrder(TreeNode *node){ if(node == nullptr) return; inOrder(node -> left); resNode -> right = node; node -> left = nullptr; resNo
2021-04-25 14:52:42
97
原创 LeetCode每日一题_21_04_24(377. 组合总和 IV)
377. 组合总和 ⅣLeetCode每日一题 2021/4/24//解法1class Solution{public: int dp[1005]; int dfs(const vector<int> &nums, int target){ if(dp[target] != -1) return dp[target]; int ans = 0; for(int i : nums){ if(i > target) break; if(i ==
2021-04-24 10:29:08
106
原创 LeetCode每日一题_21_04_22(368. 最大整除子集)
368. 最大整除子集LeetCode每日一题 2021/4/23class Solution{public: vector<int> largestDivisibleSubset(vector<int> &nums){ int len = nums.size(); if(len < 2) return nums; sort(nums.begin(), nums.end()); vector<int> dp(len, 1);
2021-04-23 09:20:33
135
原创 剑指Offer 3 - 13
剑指Offer03 - 1303. 数组中重复的数字class Solution{public: int findRepeatNumber(vector<int> &nums){ int i = 0, len = nums.size(); while(i < len){ if(nums[i] == i){ i++; continue; } if(nums[i] == nums[nums[i]]) return nums[i];
2021-04-22 16:20:55
91
原创 LeetCode每日一题_21_04_21
LeetCode每日一题——解码方法https://leetcode-cn.com/problems/decode-ways///动态规划class Solution{public: int numDecodings(string s) { int len = s.size(); if(len == 0) return 0; if(len == 1) return s == "0" ? 0 : 1; s = " "
2021-04-21 08:43:28
98
原创 L2-004 这是二叉搜索树吗?
L2-004 这是二叉搜索树吗?https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192#include <iostream>#include <vector>using namespace std;bool isMirror = false;vector<int> pre, post;void getPost(int root, int tail){
2021-04-20 22:30:53
89
原创 LeetCode每日一题_21_04_20
LeetCode每日一题——实现strStr()https://leetcode-cn.com/problems/implement-strstr///暴力法class Solution{public: int strStr(string s, string p) { int n = s.size(), m = p.size(); if(n == 0 && m != 0) return -1;//特判:当s为空并且p不为空的时候,
2021-04-20 08:56:18
109
原创 LeetCode每日一题_21_04_19
LeetCode每日一题——删除有序数组中的重复项https://leetcode-cn.com/problems/remove-element/class Solution{public: int removeElement(vector<int> &nums, int val) { int len = nums.size(); if(len == 0) return 0;//特判,如果nums中没有元素,返回0
2021-04-19 08:10:57
90
原创 LeetCode每日一题——删除有序数组中的重复项
LeetCode每日一题——删除有序数组中的重复项https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/class Solution{public: int removeDuplicates(vector<int> &nums){ int len = nums.size(); if(len == 0) return {};//特判,当输入为空数组的时候返回null if(len =
2021-04-18 08:51:58
92
原创 STL常见容器
STL常见容器序列式容器1. vector(array)vector, vector 与数组array类似。array是C++11标准中新添加的,不可改变容器的大小,遇到空间不足的情况需要创造更大的空间,并把之前的数据拷贝到新空间中,array是存储在栈中的,所以速度更快。vector使用更加灵活的动态空间来进行配置。在空间不足的时候,vector可以自动扩展空间容纳新元素,做到按需供给。在扩充空间的过程中仍然需要的是,重新分配空间、移动数据、释放原空间2. deque(queue、st
2021-04-17 14:35:26
2683
原创 多线程编程(一)
多线程编程题目地址:https://leetcode-cn.com/problemset/concurrency/1114—按序打印(使用信号量)#include <semaphore.h>class Foo{protected: sem_t firstThread;//信号量1:代表线程1是否完成 sem_t secondThread;//信号量2:代表线程2是否完成 public: Foo(){ sem_init(&firstThread, 0, 0); //
2021-04-17 09:57:30
135
原创 算法笔记学习记录
算法笔记学习记录地址前面的题目没什么难度,所以从题目G开始问题 G: 例题5-7 求圆周率pi的近似值题目描述用如下公式求圆周率PI的近似值,直到发现某一项的绝对值小于10-6为止(该项不累加)。要求输出的结果总宽度占10位,其中小数部分为8位。程序中使用浮点型数据时,请定义为双精度double类型。如果需要计算绝对值,可以使用C语言数学库提供的函数fabs,如求x的绝对值,则为fabs(x).输入无输出PI=圆周率的近似值输出的结果总宽度占10位,其中小数部分为8位。末尾输
2020-05-27 09:53:09
354
原创 算法笔记的学习记录
算法笔记的学习记录100000567 - 《算法笔记》2.3小节——C/C++快速入门->选择结构地址《算法笔记》2.3小节问题 A: 例题4-1 一元二次方程求根题目描述求一元二次方程ax2+bx+c=0的根,三个系数a, b, c由键盘输入,且a不能为0,但不保证b2-4ac>0。程序中所涉及的变量均为double类型。输入以空格分隔的一元二次方程的三个系数,双精度double类型输出分行输出两个根如下(注意末尾的换行):r1=第一个根r2=第二个根结果输出时,宽度
2020-05-23 10:22:50
233
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人