Skip to content

Latest commit

 

History

History
executable file
·
53 lines (25 loc) · 1.34 KB

344. Reverse String.md

File metadata and controls

executable file
·
53 lines (25 loc) · 1.34 KB

#

一天一道LeetCode

本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github

欢迎大家关注我的新浪微博,我的新浪微博

欢迎转载,转载请注明出处

##(一)题目

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

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

##(二)解题

题目大意:给定一个链表,将其反转输出。

解题思路:从尾到头,依次叠加到新string。

class Solution {

public:

    string reverseString(string s) {

        int len = s.length();

        string ret;

        for(int i = len-1; i>=0;i--){

            ret+=s[i];

        }

        return ret;

    }

};