本文主要是介绍【LC刷题】DAY07:344 541 54,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【LC刷题】DAY07:344 541 54
文章目录
- 【LC刷题】DAY07:344 541 54
- 344. 反转字符串 [link](https://leetcode.cn/problems/reverse-string/description/)
- 541. 反转字符串 II [link](https://leetcode.cn/problems/reverse-string-ii/description/)
- 54. 替换数字[link](https://kamacoder.com/problempage.php?pid=1064)
344. 反转字符串 link
class Solution {
public:void reverseString(vector<char>& s) {int start = 0, end = s.size() - 1;while(start < end){char tmp = s[start];s[start] = s[end];s[end] = tmp;start ++;end --; } }
};
541. 反转字符串 II link
class Solution {
public:string reverseStr(string s, int k) {int n = s.size();for (int i = 0; i < n; i += 2 * k) {int j = min(i + k, n) - 1;reverse(s, i, j);}return s;}void reverse(string& s, int left, int right) {while (left < right) {char tmp = s[left];s[left] = s[right];s[right] = tmp;left++;right--;}}
};
54. 替换数字link
#include <iostream>
#include <string.h>
using namespace std;int main(){string s;cin >>s;string tmp;for(char ss : s){if(ss >= '0' && ss <= '9'){tmp += "number";}else{tmp += ss;}}cout<<tmp;return 0;
}
这篇关于【LC刷题】DAY07:344 541 54的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!