首页 > 编程 > C++ > 正文

344. Reverse String(C++)

2019-11-06 07:03:57
字体:
来源:转载
供稿:网友

题目:

Write a function that takes a string as input and returns the string reversed. 造一个方法让输入的的字符串反转(这个不用谷歌我也可以翻译hh) Example: Given s = “hello”, return “olleh”.

直接贴代码:

class Solution {public: string reverseString(string s) { int i=0,j=s.size()-1; while(i<j) { swap(s[i],s[j]); i++; j--; } return s; }};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选