Eagle233-Blog

Categories Algorithms

40 posts

[Algorithms] 二叉树的层序遍历


Categories Algorithms BinaryTree | Tags

来源:代码随想录 二叉树的层序遍历LeetCode 102. 二叉树的层序遍历 /** * Definition for a binary tree node. * struct Tre...

[Algorithms] 二叉树的迭代遍历


Categories Algorithms BinaryTree | Tags

来源:代码随想录 LeetCode 144. 二叉树的前序遍历 LeetCode 145. 二叉树的后序遍历 LeetCode 94. 二叉树的中序遍历 掌握一种迭代方法(非统一/...

[Algorithms] 二叉树的递归遍历


Categories Algorithms BinaryTree | Tags

来源:代码随想录 LeetCode 144. 二叉树的前序遍历 LeetCode 145. 二叉树的后序遍历 LeetCode 94. 二叉树的中序遍历 前序/** * Definitio...

[Algorithms] LeetCode 347. 前 K 个高频元素


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 347. 前 K 个高频元素 优先队列 小顶堆重载的操作必须是公开的;元素、底层容器、比较函数被定义在优先队列中;输出要倒序。 取出头部元素竟然用的是qu...

[Algorithms] LeetCode 239. 滑动窗口最大值


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 239. 滑动窗口最大值 自定义单调队列注意检查非空;注意第一次要加入最大值;注意单调队列如何维持;注意弹出时要判断是否需要弹出。 class Solut...

[Algorithms] LeetCode 150. 逆波兰表达式求值


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 150. 逆波兰表达式求值 栈模拟注意string的输入输出处理,小心负数。 class Solution { public: int ...

[Algorithms] LeetCode 1047. 删除字符串中的所有相邻重复项


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 1047. 删除字符串中的所有相邻重复项 栈模拟注意是两两删除。 class Solution { public: string rem...

[Algorithms] LeetCode 20. 有效的括号


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 20. 有效的括号 栈模拟注意最后判断空栈。 class Solution { public: bool isValid(string ...

[Algorithms] LeetCode 225. 用队列实现栈


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 225. 用队列实现栈 单个队列模拟栈class MyStack { public: queue<int> que; ...

[Algorithms] LeetCode 232.用栈实现队列


Categories Algorithms StackAndQueue | Tags

来源:代码随想录 LeetCode 232.用栈实现队列 直观的方法效率不高。 class MyQueue { public: stack<int> in; ...

[Algorithms] LeetCode 459. 重复的子字符串


Categories Algorithms String | Tags

来源:代码随想录 LeetCode 459. 重复的子字符串 KMP如果 len % (len - next[len - 1]) == 0并且next[len - 1] != 0 ,则说明数...

[Algorithms] LeetCode 28. 找出字符串中第一个匹配项的下标


Categories Algorithms String | Tags

来源:代码随想录 LeetCode 28. 找出字符串中第一个匹配项的下标 KMPKMP实际上是优化过的滑动窗口,只不过优化得有点太巧妙了。 看这个视频:Knuth–Morris–Pratt...

[Algorithms] KamaCoder 55. 右旋字符串(第八期模拟笔试)


Categories Algorithms String | Tags

来源:代码随想录 KamaCoder 55. 右旋字符串(第八期模拟笔试) 三次反转#include <bits/stdc++.h> using namespace std; in...

[Algorithms] LeetCode 151. 反转字符串中的单词


Categories Algorithms String | Tags

来源:代码随想录 LeetCode 151. 反转字符串中的单词 stringstream利用stringstream可以快速分割单词。每个单词反转后再全部反转。 class Solutio...

[Algorithms] KamaCoder 54. 替换数字(第八期模拟笔试)


Categories Algorithms String | Tags

来源:代码随想录 KamaCoder 54. 替换数字(第八期模拟笔试) 双指针每次遇到数字都把第二个指针指向五个元素后,将字符串复制到后面。 #include <bits/stdc+...

[Algorithms] LeetCode 541. 反转字符串 II


Categories Algorithms String | Tags

来源:代码随想录 LeetCode 541. 反转字符串 II 单指针玩几天脑子进水了,这题都不会做了。后继比较难的可以直接用reverse,没必要再自己写了。 class Solution...

[Algorithms] LeetCode 344. 反转字符串


Categories Algorithms String | Tags

来源:代码随想录 LeetCode 344. 反转字符串 单指针class Solution { public: void reverseString(vector<...

[Algorithms] LeetCode 18. 四数之和


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 18. 四数之和 双指针两层for循环,两个剪枝,四个去重。加法数据开long long。 class Solution { public: ...

[Algorithms] LeetCode 15. 三数之和


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 15. 三数之和 双指针上一道三数之和不需要元素查重,但是本题使用map不容易查重,因此使用双指针。可以进行一次剪枝和三次查重。 三刷:双指针内部不要用w...

[Algorithms] LeetCode 383. 赎金信


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 383. 赎金信 unordered_mapclass Solution { public: bool canConstruct(str...

[Algorithms] LeetCode 454. 四数相加 II


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 454. 四数相加 II unordered_mapkey存和,value存出现次数。!!! class Solution { public: ...

[Algorithms] LeetCode 1. 两数之和


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 1. 两数之和 迭代器用法要保存下标,所以用map。注意迭代器用法。 class Solution { public: vector&l...

[Algorithms] LeetCode 202. 快乐数


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 202. 快乐数 用unordered_set保存出现过的结果四刷:先插入再更新。 class Solution { public: i...

[Algorithms] LeetCode 349. 两个数组的交集


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 349. 两个数组的交集 unordered_set考察unordered_set用法。注意插入操作、查询操作、转换为别的容器的做法。 class Sol...

[Algorithms] LeetCode 242. 有效的字母异位词


Categories Algorithms HashTable | Tags

来源:代码随想录 LeetCode 242. 有效的字母异位词 数组作为哈希表class Solution { public: bool isAnagram(string ...

[Algorithms] LeetCode 142. 环形链表 II


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 142. 环形链表 II 双指针没什么好说的,写到就是赚到,没写到就偶偶偶买嘎了。 一个走1一个走2,碰到的时候同时移动头节点和其中一个节点,相遇的就是入...

[Algorithms] LeetCode 面试题 02.07. 链表相交


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 面试题 02.07. 链表相交 求长度之差比谁长,谁长谁先走,最后一起走,走到一样的就返回。 /** * Definition for singly-l...

[Algorithms] LeetCode 19. 删除链表的倒数第 N 个结点


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 19. 删除链表的倒数第 N 个结点 双指针虚拟头节点很管用,经常能够应付莫名其妙的空指针问题。其实也不是莫名其妙,只是能给自己少找点麻烦。就像高中的时候...

[Algorithms] LeetCode 24. 两两交换链表中的节点


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 24. 两两交换链表中的节点 三指针三指针,其中当前指针只要定义一个,其他两个在while循环里面定义就好,这样在判断时只有一个变量,也只要改变一次cur...

[Algorithms] 待复习


Categories Algorithms | Tags

20250407// 20250414 !// 20250421LeetCode 977. 有序数组的平方 // 20250414 !...

[Algorithms] LeetCode 206. 反转链表


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 206. 反转链表 双指针这题又忘记怎么做了。只需要cur pre两个指针,一开始各自指向head nullptr. /** * Definition ...

[Algorithms] LeetCode 707. 设计链表


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 707. 设计链表 单链表链表问题不大,cpp语法问题很大,构造函数都不会写。MyLinkedList是构造函数,变量不用类型是因为在私有里面已经声明过了...

[Algorithms] LeetCode 203. 移除链表元素


Categories Algorithms LinkedList | Tags

来源:代码随想录 LeetCode 203. 移除链表元素 虚拟头节点 Dummy Head这题没一遍过,因为并不是每次循环都要把指针指向下一个节点,如果进行了删除操作,那么下一个节点还需要...

[Algorithms] KamaCoder 44. 开发商购买土地(第五期模拟笔试)


Categories Algorithms Array | Tags

来源:代码随想录 KamaCoder 44. 开发商购买土地(第五期模拟笔试) 前缀和Plus。有两种划分,那么分别开两个数组,把二维数组从行列两个方向压缩成列行和,然后再用前缀和。观察到求...

[Algorithms] KamaCoder 58. 区间和(第九期模拟笔试)


Categories Algorithms Array | Tags

来源:代码随想录 KamaCoder 58. 区间和(第九期模拟笔试) 前缀和的思想。 #include <bits/stdc++.h> using namespace std; ...

[Algorithms] LeetCode 59. 螺旋矩阵 II


Categories Algorithms Array | Tags

来源:代码随想录 LeetCode 59. 螺旋矩阵 II 考察基本功啊,区间统一左闭右开,最后记得处理n为奇数的情况。 class Solution { public: ...

[Algorithms] LeetCode 209. 长度最小的子数组


Categories Algorithms Array | Tags

来源:代码随想录 LeetCode 209. 长度最小的子数组 滑动窗口,注意指针什么时候要++。指针最好不要定义在for循环里面,有时候要回去–,很乱,不如直接手动++。 三刷发现忘记左边...

[Algorithms] LeetCode 977. 有序数组的平方


Categories Algorithms Array | Tags

来源:代码随想录 LeetCode 977. 有序数组的平方 双指针法,倒序写进结果数组。 四刷:指针可以取等,为什么? class Solution { public: ...

[Algorithms] LeetCode 27. 移除元素


Categories Algorithms Array | Tags

来源:代码随想录 LeetCode 27. 移除元素 暴力解法这边先要初始化一个size变量,原因是我们需要一直变动size的大小,不希望更改实际size之外的数组部分。 class Sol...

[Algorithms] LeetCode 704. 二分查找


Categories Algorithms Array | Tags

来源:代码随想录 LeetCode 704. 二分查找 注意区间的写法,我这里是左闭右开。CPP中很多STL容器都是左闭右开的,统一一下写法。 class Solution { p...


© 2025 Eagle233
Powered By Hexo & Theme mdsuper
Search