344. Reverse String
Write a function that takes a string as input and returns the string reversed.
题目大意:反向输出字符串
Example:
Given s = "hello", return "olleh".
代码如下
C++
class Solution {
public:
string reverseString(string s) {
int a = s.size()-1;
string b = "";
for(int i=a;i>=0;i--)
b += s[i];
return b;
}
};
注意:设置a是为了不用每次循环都执行s.size()-1
字符串反转实现
本文介绍了一种简单的字符串反转方法,通过C++代码示例展示了如何从输入的字符串中逐字符读取并反向拼接成新的字符串。这种方法适用于基本的字符串处理任务。
1828

被折叠的 条评论
为什么被折叠?



