![](https://img-blog.csdnimg.cn/20190918140158853.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Leetcode算法之路-Medium
Leetcode中等题记录
Love 6
腾讯WXG在职后台小鹅
展开
-
Leetcode 437. 路径总和 III(DAY 323)---- 后端面试题
Leetcode437.路径总和III(DAY323)----后端面试题。原创 2022-07-16 11:14:17 · 1916 阅读 · 0 评论 -
Leetcode 946. 验证栈序列(DAY 322)---- 后端面试题
代码】Leetcode946.验证栈序列(DAY322)----后端面试题。原创 2022-07-15 11:00:41 · 1470 阅读 · 0 评论 -
Leetcode 395. 至少有 K 个重复字符的最长子串(DAY 320)---- 后端面试题
文章目录原题题目代码实现(首刷看解 分治法)原题题目在这里插入图片描述代码实现(首刷看解 分治法)原创 2022-07-12 10:59:58 · 1591 阅读 · 0 评论 -
Leetcode 71. 简化路径(DAY 313)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目在这里插入图片描述代码实现(首刷自解)class Solution { public: string GetNextPath(const string& path, int& pos) { ++pos; string retpath; while (pos < path.size() && path[pos] != '/') { retpath += path[pos++]; } retur原创 2022-06-18 10:54:29 · 148 阅读 · 0 评论 -
Leetcode 402. 移掉 K 位数字(DAY 301)---- 后端面试题
文章目录原题题目代码实现(首刷自解 DAY 301 C++)原题题目代码实现(首刷自解 DAY 301 C++)class Solution { public: string removeKdigits(string num, int k) { int needchrs = num.size() - k; if (needchrs == 0) { return "0"; } vector<char> vec; int原创 2022-05-23 09:40:47 · 134 阅读 · 0 评论 -
Leetcode 498. 对角线遍历(DAY 300)---- 后端面试题
文章目录原题题目代码实现(首刷自解 做了很久)原题题目代码实现(首刷自解 做了很久)class Solution { public: vector<int> findDiagonalOrder(vector<vector<int>>& mat) { vector<int> ret; int level = 0, maxlevel = mat.size() + mat[0].size() - 2; bool原创 2022-05-21 10:28:47 · 284 阅读 · 0 评论 -
Leetcode 165. 比较版本号(DAY 287)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution { public: int compareVersion(string version1, string version2) { version1 += '.'; version2 += '.'; int start1 = 0, size1 = version1.size(); int start2 = 0, size2 = version2.size();原创 2022-05-07 10:30:37 · 409 阅读 · 0 评论 -
Leetcode 260. 只出现一次的数字 III(DAY 263)---- 后端面试题
文章目录原题题目代码实现(首刷看解 异或分组)原题题目代码实现(首刷看解 异或分组)class Solution {public: vector<int> singleNumber(vector<int>& nums) { int dif = 0; for(const auto& num:nums) dif ^= num; int diff_bit = -1;原创 2022-03-11 09:17:06 · 7523 阅读 · 0 评论 -
Leetcode 137. 只出现一次的数字 II(DAY 263)---- 后端面试题
文章目录原题题目代码实现(首刷看解 位运算 每位应为3的倍数)原题题目代码实现(首刷看解 位运算 每位应为3的倍数)class Solution {public: int singleNumber(vector<int>& nums) { vector<int> cnt(32,0); int res = 0; for(const auto& num:nums) {原创 2022-03-11 09:02:27 · 1069 阅读 · 0 评论 -
Leetcode 994. 腐烂的橘子(DAY 262)---- 后端面试题(2020.1.5 华为机试真题)
文章目录原题题目代码实现(首刷自解 双百 挺简单的)原题题目代码实现(首刷自解 双百 挺简单的)class Solution {public: inline void get_badorange(vector<vector<int>>& grid,vector<pair<int,int>>& next,int& fresh_oranges,int x,int y) { if(x <原创 2022-03-10 09:55:56 · 1116 阅读 · 0 评论 -
Leetcode 451. 根据字符出现频率排序(DAY 263)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: string frequencySort(string s) { unordered_map<char,int> map; priority_queue<pair<int,char>> queue; for(const auto& chr:s) ++map原创 2022-03-10 08:55:10 · 176 阅读 · 0 评论 -
Leetcode 24. 两两交换链表中的节点(DAY 262)---- 后端面试题
文章目录原题题目代码实现(首刷自解 递归)代码实现(首刷自解 迭代)原题题目代码实现(首刷自解 递归)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {}原创 2022-03-09 09:55:33 · 188 阅读 · 0 评论 -
Leetcode 117. 填充每个节点的下一个右侧节点指针 II(DAY 260)---- 后端面试题
文章目录原题题目代码实现(首刷看了一下思路 恍然大悟 没想到模拟层序遍历 一直在想递归怎么能够实现 记录左右节点)原题题目代码实现(首刷看了一下思路 恍然大悟 没想到模拟层序遍历 一直在想递归怎么能够实现 记录左右节点)class Solution {public: Node* connect(Node* root) { if(!root) return root; auto nowptr = root; while(nowpt原创 2022-03-07 10:15:34 · 141 阅读 · 0 评论 -
Leetcode 剑指 Offer 36. 二叉搜索树与双向链表(DAY 260)---- 后端面试题
文章目录原题题目代码实现(首刷自解 递归解法 C++)代码实现(首刷自解 迭代解法 C++)原题题目代码实现(首刷自解 递归解法 C++)class Solution {public: Node* pre = nullptr,*first = nullptr,*last = nullptr; void inordered_visit(Node* root) { if(!root) return; inordered_visi原创 2022-03-07 09:26:50 · 303 阅读 · 0 评论 -
Leetcode 443. 压缩字符串(DAY 258)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: int compress(vector<char>& chars) { char prechr = 0; int times = 0,ret = 0; chars.emplace_back(0); for(const auto& chr:chars)原创 2022-03-05 11:04:52 · 372 阅读 · 0 评论 -
Leetcode 695. 岛屿的最大面积(DAY 255)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: void depth_first_search(const vector<vector<int>>& grid,vector<vector<bool>>& visit,int& tmp,int x,int y) { if(x < 0 || x >= grid.siz原创 2022-03-02 09:39:43 · 116 阅读 · 0 评论 -
Leetcode 468. 验证IP地址(DAY 254)---- 后端面试题
文章目录原题题目代码实现(首刷自解 面试遇到这种题 那就太逆天了)原题题目代码实现(首刷自解 面试遇到这种题 那就太逆天了)class Solution {public: string judge_ip(const string& queryIP,int pos,int times,int ip_type) { if(pos == queryIP.size()) { if(ip_type == 0 &&原创 2022-03-01 09:21:11 · 2917 阅读 · 0 评论 -
Leetcode 12. 整数转罗马数字(DAY 251)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: string intToRoman(int num) { vector<pair<int,string>> cnt{{1000,"M"},{900,"CM"},{500,"D"},{400,"CD"}, {100,"C"},{90,"XC"},{50,原创 2022-02-26 09:30:28 · 145 阅读 · 0 评论 -
Leetcode 1209. 删除字符串中的所有相邻重复项 II(DAY 250)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: string removeDuplicates(string s, int k) { string ret; ret += s[0]; char prechr = s[0]; int size = s.size(); stack<int> stack; stack原创 2022-02-22 11:16:11 · 81 阅读 · 0 评论 -
Leetcode 1493. 删掉一个元素以后全为 1 的最长子数组(DAY 249)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: int longestSubarray(vector<int>& nums) { int left = 0,right = 0,del_num = 0,ret = 0,sum = 0; int size = nums.size(); while(right < size) {原创 2022-02-21 12:39:33 · 207 阅读 · 0 评论 -
Leetcode 781. 森林中的兔子(DAY 247)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: int numRabbits(vector<int>& answers) { sort(answers.begin(),answers.end()); int times = 1,prenum = answers[0],ret = 0,size = answers.size(); for(int i =原创 2022-02-19 11:34:08 · 186 阅读 · 0 评论 -
Leetcode 剑指 Offer 49. 丑数(DAY 246)---- 后端面试题
文章目录原题题目代码实现(首刷小部分看解 三指针优化不会 只能使用最小堆处理 unordered_set排除冗杂)原题题目代码实现(首刷小部分看解 三指针优化不会 只能使用最小堆处理 unordered_set排除冗杂)class Solution {public: int nthUglyNumber(int n) { priority_queue<long,vector<long>,greater<long>> queue;原创 2022-02-18 11:05:41 · 224 阅读 · 0 评论 -
Leetcode 剑指 Offer 04. 二维数组中的查找(DAY 246)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: bool findNumberIn2DArray(vector<vector<int>>& matrix, int target) { if(matrix.empty()) return false; int x = 0,y = matrix[0].size() - 1;原创 2022-02-18 10:18:02 · 144 阅读 · 0 评论 -
Leetcode 1166. 设计文件系统(DAY 245)---- 后端面试题
文章目录原题题目代码实现(首刷自解 暴力哈希表算法 C++)原题题目代码实现(首刷自解 暴力哈希表算法 C++)class FileSystem {public: unordered_map<string,int> map; FileSystem() {} bool createPath(string path, int value) { int pos = path.size() - 1; while(path原创 2022-02-17 11:42:21 · 202 阅读 · 0 评论 -
Leetcode 253. 会议室 II(DAY 244)---- 后端面试题
文章目录原题题目代码实现(首刷自解 查重区间)原题题目代码实现(首刷自解 查重区间)class Solution {public: int minMeetingRooms(vector<vector<int>>& intervals) { sort(intervals.begin(),intervals.end(),[&](const auto& a,const auto& b) {原创 2022-02-16 12:19:40 · 453 阅读 · 0 评论 -
Leetcode 1100. 长度为 K 的无重复字符子串(DAY 244)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: int numKLenSubstrNoRepeats(string s, int k) { if(k > 26 || s.size() < k) return 0; vector<int> cnt(26,0); unordered_set<char> set; int原创 2022-02-16 10:47:08 · 363 阅读 · 0 评论 -
Leetcode 1343. 大小为 K 且平均值大于等于阈值的子数组数目(DAY 242)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: int numOfSubarrays(vector<int>& arr, int k, int threshold) { int sum = 0,ret = 0,pow_threshold = threshold * k; for(int i = 0;i < k;++i) sum += ar原创 2022-02-13 09:54:03 · 902 阅读 · 0 评论 -
Leetcode 面试题 01.07. 旋转矩阵(DAY 241)---- 后端面试题
文章目录原题题目代码实现(首刷自解 对称镜像 45°再对称即可)原题题目代码实现(首刷自解 对称镜像 45°再对称即可)class Solution {public: void rotate(vector<vector<int>>& matrix) { int x = matrix.size(),y = matrix[0].size(); for(int row = 0;row < x/2;++row)原创 2022-02-12 10:24:44 · 89 阅读 · 0 评论 -
Leetcode 95. 不同的二叉搜索树 II(DAY 240)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)/** * 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(原创 2022-02-11 11:04:23 · 541 阅读 · 0 评论 -
Leetcode 907. 子数组的最小值之和(DAY 239)---- 后端面试题
文章目录原题题目代码实现(首刷小部分看解 单调栈 + 公式推导 难)原题题目代码实现(首刷小部分看解 单调栈 + 公式推导 难)class Solution {public: void get_left_right(vector<int>& arr,vector<int>& target,bool rev) { stack<int> stack; stack.emplace((rev ? a原创 2022-02-09 10:49:38 · 464 阅读 · 0 评论 -
Leetcode 567. 字符串的排列(DAY 232)---- 后端面试题
文章目录原题题目代码实现(首刷看了点思路后自解 滑动窗口类型 关键在于对两个容器直接相等比较)原题题目代码实现(首刷看了点思路后自解 滑动窗口类型 关键在于对两个容器直接相等比较)class Solution {public: bool checkInclusion(string s1, string s2) { vector<int> hash1(26,0),hash2(hash1); for(const auto& chr:s原创 2022-01-27 10:18:11 · 258 阅读 · 0 评论 -
Leetcode 518. 零钱兑换 II(DAY 232)---- 后端面试题
文章目录原题题目代码实现(首刷大部分看解 注意外层循环)原题题目代码实现(首刷大部分看解 注意外层循环)class Solution {public: int change(int amount, vector<int>& coins) { vector<int> dp(amount+1,0); dp[0] = 1; for(const auto& coin:coins)原创 2022-01-27 09:26:07 · 284 阅读 · 0 评论 -
Leetcode 面试题 01.05. 一次编辑(DAY 231)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: bool oneEditAway(string first, string second) { vector<vector<int>> dp(first.size()+1,vector<int>(second.size()+1,0)); int size1 = first.size(),size2 = s原创 2022-01-26 13:10:45 · 461 阅读 · 0 评论 -
Leetcode 74. 搜索二维矩阵(DAY 231)---- 后端面试题
文章目录原题题目代码实现(首刷自解 二分查找)原题题目代码实现(首刷自解 二分查找)class Solution {public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int l = matrix[0].size() - 1,r = 0; while(l >= 0 && r < matrix.size())原创 2022-01-25 09:34:41 · 212 阅读 · 0 评论 -
Leetcode 97. 交错字符串(DAY 230)---- 后端面试题(复健期)
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: bool isInterleave(string s1, string s2, string s3) { if(s1.size() + s2.size() != s3.size()) return false; vector<vector<bool>> dp(s1.size()+1,vect原创 2022-01-18 11:49:59 · 205 阅读 · 0 评论 -
Leetcode 692. 前K个高频单词(DAY 221)---- 后端面试题
文章目录原题题目代码实现(首刷自解 灵活使用优先队列)原题题目代码实现(首刷自解 灵活使用优先队列)class Solution {public: class node { public: string str; int times; node() {} node(string& s,int num):str(s),times(num) {} bool operator原创 2021-12-10 11:24:52 · 299 阅读 · 0 评论 -
Leetcode 59. 螺旋矩阵 II(DAY 216)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)class Solution {public: vector<vector<int>> generateMatrix(int n) { vector<vector<int>> ret(n,vector<int>(n,0)); int num = 1,max_num = n*n; int left = 0,righ原创 2021-12-05 14:18:31 · 289 阅读 · 1 评论 -
Leetcode 143. 重排链表(DAY 216)---- 后端面试题
文章目录原题题目代码实现(首刷自解 最优解 链表反转 + 找中点)原题题目代码实现(首刷自解 最优解 链表反转 + 找中点)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(n原创 2021-12-05 13:36:12 · 408 阅读 · 0 评论 -
Leetcode 92. 反转链表 II(DAY 215)---- 后端面试题
文章目录原题题目代码实现(首刷自解 一次遍历)原题题目代码实现(首刷自解 一次遍历)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * Li原创 2021-12-04 10:27:41 · 502 阅读 · 0 评论 -
Leetcode 82. 删除排序链表中的重复元素 II(DAY 215)---- 后端面试题
文章目录原题题目代码实现(首刷自解)原题题目代码实现(首刷自解)/** * 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原创 2021-12-04 09:56:47 · 418 阅读 · 0 评论