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/

时间: 2024-10-14 10:16:25

LeetCode之344. Reverse String的相关文章

【leetcode】344. Reverse String

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

【一天一道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". (二)解题 题目大意:给定一个链表,将

[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刷题记录[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 字符串

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) {        

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

问题: Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 大意: 写一个函数获取输入的字符串然后返回反转后后的字符串. 比如: 给出s = "hello",返回"olleh" 思路: 思路很直接就想到,先把字符串拆分成一个个字符组成的

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.如果对指针操作还不熟练,可以通过另分配n个字节的内存来进行翻转.即将字符串从后向前读,然后从前向后保存在新内存中,再将指针指向新内存. 代码如下:(如果不把strlen(s)保