青叶摩卡
青叶摩卡
全部文章
分类
归档
标签
去牛客网
登录
/
注册
青叶摩卡的博客
TA的专栏
0篇文章
0人订阅
面试高频榜单思路
0篇文章
0人学习
面试高频榜单思路梳理
0篇文章
0人学习
面试高频榜单思路梳理
0篇文章
0人学习
全部文章
(共136篇)
题解 | #对称的二叉树#
递归class Solution { public: bool isSymmetrical2(TreeNode* l, TreeNode* r) { if ((l != nullptr) ^ (r != nullptr)) return false; if (...
2022-12-08
0
128
题解 | #二叉树的下一个结点#
基本思路:如果有右子树,找右子树中的最左节点如果没有右子树,向上遍历直到根节点或者为某个树的左子树,中序遍历下一个节点即为该左子树的根节点class Solution { public: TreeLinkNode* GetNext(TreeLinkNode* pNode) { ...
2022-12-08
0
182
题解 | #删除链表中重复的结点#
三个指针分别指向前中后三个节点,如果中间节点与后面节点的值相等,就开一个循环把其中相等的值全删掉。class Solution { public: ListNode* deleteDuplication(ListNode* pHead) { if (!pHead || !pH...
2022-12-08
0
175
题解 | #链表中环的入口结点#
快慢指针,求解链表环的模板解法。class Solution { public: ListNode* EntryNodeOfLoop(ListNode* pHead) { if (!pHead || !pHead->next) return nullptr; ...
2022-12-07
0
138
题解 | #字符流中第一个不重复的字符#
class Solution { public: vector<char> v; unordered_map<char, int> hash; //Insert one char from stringstream void Insert(char...
2022-12-07
0
176
题解 | #构建乘积数组#
前缀和思想,两遍遍历,第一遍计算前缀积,第二遍计算后缀积并与同一下标的前缀积相乘。class Solution { public: vector<int> multiply(const vector<int>& A) { int n = A.s...
2022-12-07
0
138
题解 | #数组中重复的数字#
利用数组元素都在0~n-1的性质,记录已经出现过的数class Solution { public: bool duplicate(int numbers[], int length, int* duplication) { for (int i = 0; i < le...
2022-12-07
0
168
题解 | #把字符串转换成整数#
class Solution { public: int StrToInt(string str) { if (str == "") return 0; long long res = 0; bool up = true; in...
2022-12-07
0
174
题解 | #不用加减乘除做加法#
唔。。。建议具体思路看官方题解,不过我还是建议背下来class Solution { public: int Add(int num1, int num2) { while (num2) { int sum = num1 ^ num2; ...
2022-12-07
0
148
题解 | #求1+2+3+...+n#
基本思路:高斯公式n * (n + 1) / 2只能用加减、位操作、逻辑,所以用快速乘来实现n * (n + 1)快速乘需要一次判断,当最低位为0时才相加,考虑用短路操作实现判断逻辑。n最大也只有200,换算成二进制也就是9位,所以把循环展开9次就行了(实际上8次就够了)class Solution...
2022-12-07
0
135
首页
上一页
4
5
6
7
8
9
10
11
12
13
下一页
末页