-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.xml
More file actions
39 lines (39 loc) · 5.19 KB
/
Copy pathindex.xml
File metadata and controls
39 lines (39 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>3000ye Code Blog</title>
<link>http://code.3000ye.com/</link>
<description>Recent content on 3000ye Code Blog</description>
<generator>Hugo</generator>
<language>en</language>
<atom:link href="http://code.3000ye.com/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Linked List</title>
<link>http://code.3000ye.com/linkedlist/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>http://code.3000ye.com/linkedlist/</guid>
<description>Linked List 21. Merge Two Sorted Lists typedef ListNode* ListLink; class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { if (list1 == nullptr) return list2; if (list2 == nullptr) return list1; // 将头节点较小的链表放在 list1 if (list1-&gt;val &gt; list2-&gt;val) swap(list1, list2); // 遍历 list2,按大小插入 list1 auto ls1 = list1, ls2 = list2; while (ls2 != nullptr) { if (ls1-&gt;next != nullptr and ls2-&gt;val &gt; ls1-&gt;next-&gt;val) {} else { // 插入节点 ListLink temp = new ListNode(ls2-&gt;val, ls1-&gt;next); ls1-&gt;next = temp; ls2 = ls2-&gt;next; } ls1 = ls1-&gt;next; } return list1; } }; typedef ListNode* ListLink; class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { ListLink res = new ListNode(0); auto p = res, p1 = list1, p2 = list2; while (p1 and p2) { if (p1-&gt;val &lt; p2-&gt;val) { p-&gt;next = p1; p1 = p1-&gt;next; } else { p-&gt;next = p2; p2 = p2-&gt;next; } p = p-&gt;next; } while (p1) { p-&gt;next = p1; p1 = p1-&gt;next; p = p-&gt;next; } while (p2) { p-&gt;next = p2; p2 = p2-&gt;next; p = p-&gt;next; } return res-&gt;next; } }; class Solution { public: ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) { if (list1 == nullptr) return list2; if (list2 == nullptr) return list1; if (list1-&gt;val &lt;= list2-&gt;val) { list1-&gt;next = mergeTwoLists(list1-&gt;next, list2); return list1; } else { list2-&gt;next = mergeTwoLists(list1, list2-&gt;next); return list2; } } }; 题面 有两个链表,其中的节点都按照节点值有序排序,请你将这两个链表合并为一个有序链表。</description>
</item>
<item>
<title>Stack</title>
<link>http://code.3000ye.com/stack/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>http://code.3000ye.com/stack/</guid>
<description>Stack 20. Valid Parentheses class Solution { public: bool isValid(string s) { stack&lt;char&gt; stk; for (auto c : s) { if (stk.size() == 0) stk.push(c); else if (stk.top() == &#39;(&#39; and c == &#39;)&#39;) stk.pop(); else if (stk.top() == &#39;[&#39; and c == &#39;]&#39;) stk.pop(); else if (stk.top() == &#39;{&#39; and c == &#39;}&#39;) stk.pop(); else stk.push(c); } return stk.size() == 0 ? true : false; } }; 题面 给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。</description>
</item>
<item>
<title>Queue</title>
<link>http://code.3000ye.com/queue/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>http://code.3000ye.com/queue/</guid>
<description>Queue 387. First Unique Character in a String class Solution { public: int firstUniqChar(string s) { int ls[200]; for (auto c : s) { ls[c] ++; } for (int i = 0, l = s.size(); i &lt; l; i ++) { if (ls[s[i]] == 1) return i; } return -1; } }; 题面 给定一个字符串 s ,找到 它的第一个不重复的字符,并返回它的索引 。如果不存在,则返回 -1 。
题解 Method One: 直接法
用一个数组记录每个字符出现的次数 遍历字符串,找到第一个只出现一次的字符 933. Number of Recent Calls class RecentCounter { private: queue&lt;int&gt; que; public: RecentCounter() {} int ping(int t) { que.</description>
</item>
<item>
<title>BinaryTree</title>
<link>http://code.3000ye.com/binarytree/</link>
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
<guid>http://code.3000ye.com/binarytree/</guid>
<description>BinaryTree 94. Binary Tree Inorder Traversal class Solution { public: vector&lt;int&gt; inorderTraversal(TreeNode* root) { vector&lt;int&gt; res; subFunction(root, res); return res; } void subFunction(TreeNode* root, vector&lt;int&gt;&amp; res) { if (root == nullptr) return; else { subFunction(root-&gt;left, res); res.push_back(root-&gt;val); subFunction(root-&gt;right, res); } } }; 题面 给定一个二叉树的根节点 root ,返回 它的 中序 遍历 。
题解 Method One: 递归
初始化一个结果数组 递归遍历二叉树,并按中根序添加元素 Method Two: 迭代
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if (p == nullptr and q == nullptr) return true; else if ((p == nullptr and q !</description>
</item>
</channel>
</rss>