会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
hjy94wo
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
下一页
2022年8月27日
LeetCode 20. 有效的括号
摘要: class Solution { public: bool isValid(string s) { stack<char> stack; for (int i = 0; i < s.size(); i ++) { if (s[i] == ')' || s[i] =='}' || s[i] == ']
阅读全文
posted @ 2022-08-27 09:10 hjy94wo
阅读(17)
评论(0)
推荐(0)
2022年8月26日
LeetCode 225. 用队列实现栈
摘要: 思路: 一个队列用于备份,先将原队列最后一位元素之前的元素弹出,push进备份队列,后再还原 class MyStack { public: queue<int> queue1; queue<int> queue2; //备份 MyStack() { } void push(int x) { que
阅读全文
posted @ 2022-08-26 19:22 hjy94wo
阅读(23)
评论(0)
推荐(0)
LeetCode 232. 用栈实现队列
摘要: 思路: 用两个栈实现队列 pop操作,若out栈为空则先将in中元素push进out,再pop出out中元素 peek操作,直接调用pop,在将pop出元素push进out class MyQueue { public: stack<int> in; stack<int> out; MyQueue(
阅读全文
posted @ 2022-08-26 19:10 hjy94wo
阅读(23)
评论(0)
推荐(0)
LeetCode 92. 反转链表 II
摘要: 思路 将子链表切割下来并记录左节点前一个节点pre和右节点下一个节点sucess 反转子链表后,pre指向反转后的子链表,左节点(此时为子链表的尾节点指向sucess) /** * Definition for singly-linked list. * struct ListNode { * in
阅读全文
posted @ 2022-08-26 10:48 hjy94wo
阅读(17)
评论(0)
推荐(0)
LeetCode 234. 回文链表
摘要: 思路: 将链表数据存入vector用双指针解决 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr)
阅读全文
posted @ 2022-08-26 10:08 hjy94wo
阅读(14)
评论(0)
推荐(0)
AcWIng 86. 分隔链表
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) :
阅读全文
posted @ 2022-08-26 09:26 hjy94wo
阅读(16)
评论(0)
推荐(0)
2022年8月24日
LeetCode 21 合并两个有序链表
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) :
阅读全文
posted @ 2022-08-24 19:15 hjy94wo
阅读(17)
评论(0)
推荐(0)
LeetCode 203. 移除链表元素
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) :
阅读全文
posted @ 2022-08-24 16:53 hjy94wo
阅读(18)
评论(0)
推荐(0)
LeetCode 142. 环形链表 II
摘要: 思路: 快慢指针法:当快指针与慢指针相遇时,分别从起点,相遇点开始走,相遇即为环入口 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)
阅读全文
posted @ 2022-08-24 14:14 hjy94wo
阅读(28)
评论(0)
推荐(0)
LeetCode 面试题 02.07. 链表相交
摘要: /** Definition for singly-linked list. struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; */ class Solution { publi
阅读全文
posted @ 2022-08-24 11:41 hjy94wo
阅读(20)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
8
下一页
公告