摘要: 【144.二叉树的前序遍历】 【145.二叉树的后序遍历】 【94.二叉树的中序遍历】 class Solution { public: vector<int> preorderTraversal(TreeNode* root) { stack<int> st; vector<int> result 阅读全文
posted @ 2022-11-24 21:10 跬步瑶 阅读(24) 评论(0) 推荐(0)
摘要: 【0347.前K个高频元素】 class Solution { public: vector<int> topKFrequent(vector<int>& nums, int k) { unordered_map <int, int> map; for (int i = 0; i < nums.si 阅读全文
posted @ 2022-11-23 20:48 跬步瑶 阅读(35) 评论(0) 推荐(0)
摘要: 【0150.逆波兰表达式求值】 class Solution { public: int evalRPN(vector<string>& tokens) { stack<long long> st1; long long temp1; long long temp2; for (int i = 0; 阅读全文
posted @ 2022-11-22 21:28 跬步瑶 阅读(75) 评论(0) 推荐(0)
摘要: 【0020.有效的括号】 class Solution { public: bool isValid(string s) { stack<char>st1; for (int i = 0; i < s.size(); i++) { if (s[i] == '(' || s[i] == '{' || 阅读全文
posted @ 2022-11-21 21:15 跬步瑶 阅读(32) 评论(0) 推荐(0)
摘要: 【0232.用栈实现队列】 class MyQueue { public: stack<int> stIn; stack<int> stOut; MyQueue() { } void push(int x) { stIn.push(x); } int pop() { int temp; if (!s 阅读全文
posted @ 2022-11-20 21:31 跬步瑶 阅读(38) 评论(0) 推荐(0)
摘要: 【面试题 02.07. 链表相交】 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} 阅读全文
posted @ 2022-11-18 21:05 跬步瑶 阅读(38) 评论(0) 推荐(0)
摘要: 【0206.翻转链表】 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNo 阅读全文
posted @ 2022-11-17 21:27 跬步瑶 阅读(38) 评论(0) 推荐(0)
摘要: 【0027.移除元素】 class Solution { public: int removeElement(vector<int>& nums, int val) { int fast = 0; int slow = 0; for (int fast = 0; fast < nums.size() 阅读全文
posted @ 2022-11-16 21:37 跬步瑶 阅读(30) 评论(0) 推荐(0)
摘要: 【0459.重复的子字符串】 class Solution { public: bool repeatedSubstringPattern(string s) { for (int i = 0; i < s.size()/2; i++) { int k = i + 1; for (int j = 0 阅读全文
posted @ 2022-11-15 18:05 跬步瑶 阅读(47) 评论(0) 推荐(0)
摘要: 【0151.翻转字符串里的单词】 class Solution { public: string reverseWords(string s) { int slow = 0; int fast = 1; while (fast < s.size()) { if (s[slow] == ' ' && 阅读全文
posted @ 2022-11-14 21:24 跬步瑶 阅读(39) 评论(0) 推荐(0)