题目描述

  • LeetCode 344. 反转字符串
  • 请编写一个函数,其功能是将输入的字符串反转过来。

示例

  • 输入: s = "hello"
  • 返回: "olleh"

Java 解答

class Solution {
public String reverseString(String s) {
if (s == null || s.length() <= 1) {
return s;
}
char[] arr = s.toCharArray();
int length = arr.length;
for (int i = 0; i < length / 2; i++) {
char temp = arr[i];
arr[i] = arr[length - i - 1];
arr[length - i - 1] = temp;
}
return String.valueOf(arr); //return new StringBuilder(s).reverse().toString();
}
}

LeetCode 344. Reverse String(反转字符串)的更多相关文章

  1. [LeetCode] 344. Reverse String 翻转字符串

    Write a function that reverses a string. The input string is given as an array of characters char[]. ...

  2. 344 Reverse String 反转字符串

    请编写一个函数,其功能是将输入的字符串反转过来.示例:输入:s = "hello"返回:"olleh"详见:https://leetcode.com/probl ...

  3. Leetcode 344:Reverse String 反转字符串(python、java)

    Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...

  4. Leetcode#344. Reverse String(反转字符串)

    题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...

  5. [LeetCode] 344 Reverse String && 541 Reverse String II

    原题地址: 344 Reverse String: https://leetcode.com/problems/reverse-string/description/ 541 Reverse Stri ...

  6. leetcode 344. Reverse String 、541. Reverse String II 、796. Rotate String

    344. Reverse String 最基础的旋转字符串 class Solution { public: void reverseString(vector<char>& s) ...

  7. Leetcode 344 Reverse String 字符串处理

    题意:反转字符串,用好库函数. class Solution { public: string reverseString(string s) { reverse(s.begin(),s.end()) ...

  8. (字符串 数组 递归 双指针) leetcode 344. Reverse String

    Write a function that reverses a string. The input string is given as an array of characters char[]. ...

  9. LeetCode 344. Reverse String

    Problem: Write a function that takes a string as input and returns the string reversed. Example: Giv ...

随机推荐

  1. shell中的$* $@

    shell中$*与$@的区别 关于$* 和 $@的 一点 认识 同是菜鸟一起学习 $* 所有的位置参数,被作为一个单词. 注意:"$*"必须被""引用. $@ ...

  2. 学习opencv-------函数使用一

    #include"head.h" //cvResize() /*int main() { IplImage *img = cvLoadImage("e:/picture/ ...

  3. Qt ------ 初始化构造函数参数,parent

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setup ...

  4. RotateAnimation 详解

    RotateAnimation 详解 看看新闻网>看引擎>开源产品 其他构造器的旋转也可参考这副图. RotateAnimation旋转坐标系为以旋转点为坐标系(0,0)点.x轴为0度,顺 ...

  5. 如何写出高性能DOM?

    为什么要写高性能DOM? 一个网站,在页面上承载最多内容的就是DOM,而且无论是我们通过加载JS.加载图片,他们也是通过写HTML标签来实现的.而我们性能优化要做的无非就是几大块: 站点的网络消耗 D ...

  6. EF数据更新时候异常情况一

    在不熟练EF的时候有时更新数据时候会报以下异常: 错误原因:此时操作的实体不是从数据库里获取的.而是自己new出来的实体然后赋值的.EF此时的存储池中已经有了这个实体,在new一个对象ID相同就不能共 ...

  7. (转)matlab练习程序(HOG方向梯度直方图)

    matlab练习程序(HOG方向梯度直方图)http://www.cnblogs.com/tiandsp/archive/2013/05/24/3097503.html HOG(Histogram o ...

  8. HDU 2577 How to Type (字符串处理)

    题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...

  9. elementui raido 单选框 循环渲染加:key

    <el-radio-group v-model="adminRole"> <el-radio v-for="item in adminRoles&quo ...

  10. postman测试express restful接口

    安装express及postman var express = require('express') var app = express(); var calculation = require('. ...