远神_
远神_
全部文章
分类
题解(29)
归档
标签
去牛客网
登录
/
注册
远神_的博客
全部文章
(共29篇)
题解 | #数组中只出现一次的数字#
hash思路map<int, int>用于记录元素和元素出现的次数最后过滤出出现一次的两个元素 class Solution { public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2)...
2021-07-25
0
312
题解 | #合并有序链表#
class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if(l1 == nullptr) return l2; if(l2 == nullptr) retu...
2021-07-25
0
339
题解 | #反转字符串#
首尾交换,直到中间下标处 class Solution { public: string solve(string str) { int len = str.size(); for(int i=0; i<len/2; ++i){ ...
2021-07-25
0
284
题解 | #反转链表#
原链表不断取头,新链表头插 class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode* newHead = nullptr; while(pHead){ ...
2021-07-25
0
264
题解 | #在二叉树中找到两个节点的最近公共祖先#
非递归方式--深度优先搜索思路很简单,深度搜索出所有路径,搜索的过程中过滤出到达o1和o2的路径保存,最后找到o1和o2的路径上的公共节点 map<TreeNode, bool> m; 记录哪个节点访问过deque<TreeNode> dq; 用于保存深度搜索路径vector...
2021-07-25
0
316
题解 | #二叉树的最大深度#
深度优先搜索--非递归 class Solution { public: /** * * @param root TreeNode类 * @return int整型 */ //dfs int maxDepth(TreeNode* r...
2021-07-25
0
263
题解 | #括号序列#
入栈要匹配的右半括号,再检查 stack<char> st; for(int i=0; i<s.size(); ++i){ if(s[i] == '{') st.push('}'); else if(s...
2021-07-25
0
302
题解 | #扑克牌顺子#
非递归方式 class Solution { public: bool hasNoChildren(TreeNode* node) { &nb...
2021-07-25
0
320
题解 | #扑克牌顺子#
思路1 借助桶结构,将牌全部放入桶中,判断连续的牌数加上0的牌数等于5一定是顺子,左右非零牌的牌中间的连续区间只要有五个元素就一定是顺子 class Solution { public: bool IsContinuous( vector<int> numbers ) { ...
2021-05-19
0
372
首页
上一页
1
2
3
下一页
末页