题目描述

  • 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();}
}

转载于:https://www.cnblogs.com/hglibin/p/8993636.html

LeetCode 344. Reverse String(反转字符串)相关推荐

  1. LeetCode 344.Reverse String

    题意: Write a function that takes a string as input and returns the string reversed. Example: Given s ...

  2. LeetCode 344. Reverse String

    题目: Write a function that takes a string as input and returns the string reversed. Example: Given s ...

  3. LeetCode: 344. Reverse String

    051102 题目 Write a function that reverses a string. The input string is given as an array of characte ...

  4. Reverse Vowels of a String (反转字符串中的母音)

    leetcode Reverse Vowels of a String 反转字符串中的母音 一.学习要点: 1.find_first_of:查找与字符串str中某个字符相同的位置,并返回他的第一个出现 ...

  5. 【跟Leon一起刷LeetCode】344. Reverse String

    Reverse String Description: Write a function that takes a string as input and returns the string rev ...

  6. LeetCode(557)——反转字符串中的单词 III(JavaScript)

    给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例1: 输入: "Let's take LeetCode contest" 输出: &qu ...

  7. LeetCode之Reverse String II

    1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...

  8. String | 344. Reverse String

    题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...

  9. (递归)LeetCode基础练习,反转字符串(递归和非递归算法)C++ Day1打卡

    344反转字符串 题目描述如下 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) ...

  10. LeetCode简单题之反转字符串

    题目 编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 s 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 示例 1: ...

最新文章

  1. Google图嵌入工业界最新大招,高效解决训练大规模深度图卷积神经网络问题
  2. 大数据教父Micheal Stonebraker告诉你大数据的秘密
  3. 第六章 深度学习(中下)
  4. CSS中的Position属性
  5. python程序打包成安卓app教程_Python打包方法基本应用方式介绍
  6. android 结束if循环_(第五讲)if 分支语句和 while 循环
  7. 最近程序员频繁被抓,如何避免面向监狱编程?!
  8. CVPR最佳作者新作!无监督学习可变形3D对象
  9. [机器学习]-[数据预处理]-中心化 缩放 KNN(二)
  10. Mac安装IDA后各版本android_server
  11. HTML简单网页-员工申请表单
  12. matlab qam调制函数,matlab实现16QAM调制解调
  13. 三大微分中值定理及泰勒中值定理证明
  14. 算法面试题-用单向链表表示十进制整数,求两个正整数之和。1234+34=1268
  15. 普元的ajax,有人了解普元 primeton EOS 产品的么?可否评价一下?
  16. 两年多的社招经验分享,我的跳槽经验总结(含阿里滴滴美团快手头条)
  17. 纳滤膜分离技术用于制药提纯精制处理 稳定可靠
  18. traceroute命令详解
  19. 一种灵活可靠的工作方式:组件化设计与开发
  20. 结合推荐营销和社交媒体的最佳实践有哪些?

热门文章

  1. 文字处理技术:标点压缩
  2. 蚂蚁如果上市成功,价格崩盘是必然的
  3. 几个月都没新增严重BUG,你测试组在干什么?
  4. JAVA:文本文件读写使用Reader/Writer,二进制文件使用InputStream/OutputStream
  5. 命令行下运行JAVA出错:错误的签名:
  6. 编译OpenCV:precomp.hpp:60:37: fatal error: dynlink_nvcuvid.h
  7. 网络正确,就是不能上网,检查WIN10代理设置
  8. 钩子函数atexit
  9. 具体化和实例化的应用
  10. stm32设备描述符请求失败_我爱OS第21讲:实战篇:IO设备