摘要: 题目 没想透的一点:对于要实现的队列的pop操作,其实先看输出栈是否为空,如果不为空,直接从输出栈弹出即可,如果为空,再将输入栈的元素依次压入输出栈(注意是全部压入输出栈,毕竟输入栈的最下面的那个元素其实是我们想要弹出的元素),再弹出输出栈的栈顶元素。 卡哥思路讲得很清晰,跟着卡哥代码敲了下: cl 阅读全文
posted @ 2025-01-21 11:07 hisun9 阅读(12) 评论(0) 推荐(0)
摘要: 题目 自己写的: class Solution { public: bool isLongPressedName(string name, string typed) { int slow = 0, fast = 0; while (fast < typed.size()) { if (slow < 阅读全文
posted @ 2025-01-18 13:57 hisun9 阅读(6) 评论(0) 推荐(0)
摘要: 题目 这道题不会,看了卡哥思路,卡哥提供了三种方法。 方法一:暴力解法 自己写的代码: class Solution { public: bool repeatedSubstringPattern(string s) { int n = s.size(); for (int len = 1; len 阅读全文
posted @ 2025-01-18 13:19 hisun9 阅读(20) 评论(0) 推荐(0)
摘要: 题目 KMP典中典,可惜我不会。 卡哥思路里的讲解也似懂非懂,跟着卡哥代码敲了一遍 class Solution { public: void getNext(int *next, const string &s) { int j = -1; next[0] = j; for (int i = 1; 阅读全文
posted @ 2025-01-16 20:23 hisun9 阅读(22) 评论(0) 推荐(0)
摘要: 题目 自己写的: #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int n; string s; cin >> n >> s; reverse(s.begin( 阅读全文
posted @ 2025-01-15 23:12 hisun9 阅读(9) 评论(0) 推荐(0)
摘要: 题目 不会做,老老实实看卡哥思路,这里面讲的很详细,有很多值得学习揣摩的东西。 在把空格处理好后,先反转整体,再反转其中的单词的方法,很值得学习。即使用整体反转+局部反转就可以实现反转单词顺序的目的 跟着卡哥代码敲了一遍: class Solution { public: void reverse( 阅读全文
posted @ 2025-01-15 23:12 hisun9 阅读(10) 评论(0) 推荐(0)
摘要: 题目 自己写的: #include <iostream> #include <string> using namespace std; int main() { string s; string t; cin >> s; for (auto c : s) { if (c >= '1' && c <= 阅读全文
posted @ 2025-01-15 15:15 hisun9 阅读(85) 评论(0) 推荐(0)
摘要: 题目 自己写的: class Solution { public: string reverseStr(string s, int k) { int n = s.size(); int cnt = 1; while (cnt * 2 * k <= n) { int t = (cnt - 1) * 2 阅读全文
posted @ 2025-01-14 20:58 hisun9 阅读(7) 评论(0) 推荐(0)
摘要: 题目 这道题很简单了,自己写的: class Solution { public: void reverseString(vector<char>& s) { int n = s.size(); for (int i = 0; i < n / 2; ++i) { char tmp; tmp = s[ 阅读全文
posted @ 2025-01-14 19:13 hisun9 阅读(5) 评论(0) 推荐(0)
摘要: 题目 这道题没写出来,主要是不知道怎么处理重复字符,看了卡哥思路,茅塞顿开。 真的是很妙的转换。 跟着卡哥代码敲的: class Solution { public: vector<string> commonChars(vector<string>& words) { vector<string> 阅读全文
posted @ 2025-01-14 14:57 hisun9 阅读(10) 评论(0) 推荐(0)