2017/11/6 Leetcode 日记

344. Reverse String

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

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

相关文章:

  • 2021-09-13
  • 2021-04-16
  • 2021-05-31
  • 2021-12-24
  • 2022-12-23
  • 2021-05-17
  • 2022-02-23
  • 2021-09-10
猜你喜欢
  • 2021-07-24
  • 2021-12-02
  • 2021-12-18
  • 2022-03-08
  • 2021-12-10
  • 2021-09-24
  • 2021-11-26
相关资源
相似解决方案