【一天一道LeetCode】#344. Reverse String

一天一道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;
    }
};
时间: 2024-11-08 17:07:44

【一天一道LeetCode】#344. Reverse String的相关文章

[LeetCode] 344 Reverse String & 541 Reverse String II

原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse String II: https://leetcode.com/problems/reverse-string-ii/description/ 题目&解法: 1.Reverse String: Write a function that takes a string as input and returns

leetCode 344. Reverse String 字符串

344. Reverse String Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 思路1: 使用一个新的string来存放结果. class Solution { public:     string reverseString(string s) {        

leetcode --344. Reverse String

Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 1 class Solution { 2 public: 3 string reverseString(string s) { 4 int i = 0 ; 5 int j = s.size()-1; 6 while(i<

Python [Leetcode 344]Reverse String

题目描述: Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 解题思路: 见代码. 代码如下: class Solution(object): def reverseString(self, s): """ :type s: str :rtype

Leetcode刷题记录[python]——344 Reverse String

一.前言 不是计算机专业出身,却有一颗程序猿的心. 昨日开始leetcode第一次刷题,选择了菜鸟方式,从AC率最高且难度为Easy的题开始,不管题是简单还是难,都想做个记录,既是方便以后回顾,又是以此作为一个激励,督促自己每天都能有所进步. 二.题344 Reverse String Write a function that takes a string as input and returns the string reversed. class Solution(object): def

【leetcode】344. Reverse String

problem 344. Reverse String 参考 1. Leetcode_344_Reverse String; 完 原文地址:https://www.cnblogs.com/happyamyhope/p/10419862.html

344. Reverse String(C++)

344. Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 题目大意: 字符串倒置. 解题方法: 第一个字符与最后一个非空字符对换. 注意事项: 1.字符串最后一个字符是空字符. C++代码: 1.不良代码: 1 class Solution

344. Reverse String【easy】

344. Reverse String[easy] Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 解法一: 1 class Solution { 2 public: 3 string reverseString(string s) { 4 int start = 0, e

LeetCode之344. Reverse String

------------------------------- Java也可以实现一行代码反转字符串哦 AC代码如下: public class Solution { public String reverseString(String s) { return new StringBuffer(s).reverse().toString(); } } 题目来源: https://leetcode.com/problems/reverse-string/