leetcode 344 Reverse String

来源:互联网 发布:数学软件有哪些 编辑:程序博客网 时间:2024/05/22 15:10

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

Subscribe to see which companies asked this question


class Solution {public:string reverseString(string s) {if(s == "") return s;for(int i = 0, j = s.size()-1; i < j; i++, j--) {char ch = s[i];s[i] = s[j];s[j] = ch;}return s;}}




0 0