Reverse String

Posted 17bdw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Reverse String相关的知识,希望对你有一定的参考价值。

Algorithm

【leetcode】Reverse String

https://leetcode.com/problems/reverse-string/

1)problem

编写一个以字符串作为输入并逆转字符串的函数。

2)answer

字符串大于0,就从最末尾开始取值。

3)solution

#include "pch.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using std::string;


class Solution {
public:
    string reverseString(string s) {

        string result = "";
        for (int i =s.length()-1;i>=0 ; i--)
        {
            result += s.at(i);
        }

        return result;

    }
};

int main()
{
    // 使用内容
    Solution nSolution;
    nSolution.reverseString("abcdef");
}

以上是关于Reverse String的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode之344. Reverse String

344. (Reverse String)反转字符串

leetcode-344. Reverse String

345. Reverse Vowels of a String

344. Reverse String

Reverse a String-freecodecamp-js题目