344.反转字符串
题目链接:https://leetcode.cn/problems/reverse-string/description/
文章讲解:https://programmercarl.com/0344.%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2.html
视频讲解:https://www.bilibili.com/video/BV1fV4y17748/?spm_id_from=333.788&vd_source=e70917aa6392827d1ccc8d85e19e8375
实现情况:
class Solution {
public:
void reverseString(vector<char>& s) {
for(int i = 0,j = s.size()-1; i<s.size()/2;i++,j--){
swap(s[i],s[j]);
}
}
};
541. 反转字符串II
题目链接:https://leetcode.cn/problems/reverse-string-ii/description/
文章讲解:https://programmercarl.com/0541.%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2II.html
视频讲解:https://www.bilibili.com/video/BV1dT411j7NN/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=e70917aa6392827d1ccc8d85e19e8375
实现情况:
class Solution {
public:
string reverseStr(string s, int k) {
for (int i = 0; i < s.size(); i += (2 * k)) {
if (i + k < s.size()) {
reverse(s.begin() + i, s.begin() + i + k);
} else {
reverse(s.begin() + i, s.end());
}
}
return s;
}
};
卡码网:54.替换数字
题目链接:https://kamacoder.com/problempage.php?pid=1064
文章讲解:https://programmercarl.com/kama54.%E6%9B%BF%E6%8D%A2%E6%95%B0%E5%AD%97.html
实现情况:
主要格式注意
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
string s;
cin>>s;
vector<char> result;
for(char c:s){
if(c <='z'&& c>='a'){
result.push_back(c);
}else{
for(char nc:string("number")){
result.push_back(nc);
}
}
}
cout << string(result.begin(), result.end());
}
标签:卡码,string,AC%,E5%,反转,https,字符串,com,reverse
From: https://blog.csdn.net/qq_43441284/article/details/140674584