题目:
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.

翻译:
写一个函数,使用字符串作为输入,返回它反转后的结果。
例如,输入”hello”,返回”olleh”。

分析:
转为字符数组后,将第一个字符和最后一个字符对调,第二个字符和倒数第二个对调,以此类推。

Java版代码(时间复杂度O(n),空间复杂度O(n)):

public class Solution {public String reverseString(String s) {char[] chars=s.toCharArray();int len=chars.length;char temp;for(int i=0;i<len/2;i++){temp=chars[i];chars[i]=chars[len-1-i];chars[len-1-i]=temp;}return new String(chars);}
}

Leet Code OJ 344. Reverse String [Difficulty: Easy]相关推荐

  1. Leet Code OJ 7. Reverse Integer [Difficulty: Easy]

    题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have ...

  2. Leet Code OJ 28. Implement strStr() [Difficulty: Easy]

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  3. Leet Code OJ 125. Valid Palindrome [Difficulty: Easy]

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  4. Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]

    题目: Given a string containing just the characters , determine if the input string is valid. The brac ...

  5. Leet Code OJ 112. Path Sum [Difficulty: Easy]

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  6. Leet Code OJ 242. Valid Anagram [Difficulty: Easy]

    题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...

  7. Leet Code OJ 1. Two Sum [Difficulty: Easy]

    题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

  8. Leet Code OJ 223. Rectangle Area [Difficulty: Easy]

    题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...

  9. Leet Code OJ 189. Rotate Array [Difficulty: Easy]

    题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the ar ...

最新文章

  1. 伦敦大学学院、UC伯克利联手,撰文综述深度强化学习泛化研究
  2. 2009年9月三级网络技术51CTO版考前压轴试题
  3. 正确地使用投影仪和移动硬盘
  4. 实现简单render函数
  5. VS系列之【 产品密钥 – 所有版本】
  6. ARM指令集发展概述
  7. vue——回到顶部监听滚动事件
  8. 判了!国内「最牛删库跑路事件」程序员被判6年,公司损失近亿
  9. 发生内部错误。请与 microsoft 支持部门联系。_设计变更、工程签证、确认单、工程洽商、联系单、会签的是干啥的?有啥区别?...
  10. 班级网站-前端网页技术精美完整源码HTML+CSS+JS
  11. font awesome矢量字体使用
  12. 锐捷交换机(S2924/2928G)光口改电口,或电口改光口的准确方法
  13. 【Linux】从冯诺依曼体系到初识Linux下的进程
  14. 目前5G SoC 芯片技术成熟吗
  15. [随手记系列]SQLite数据库.db | .db-wal | .db-shw到底是个啥,为什么我导出.db里面没数据呢?
  16. 计算机项目 rolling ball
  17. 最全最走心:模电-模拟电子技术 复试/面试知识点大总结 (已更完)
  18. 【LeNet、AlexNet、VGG】
  19. sham-link和路由选路
  20. 大数据未来应用的五大发展方向

热门文章

  1. 前驱和后驱什么意思_14.98万!造型酷似“保时捷”,后置后驱续航510,这款SUV要火...
  2. 1039. 到底买不买(20)
  3. UTC时间戳-时间字符串之间互相转化
  4. Gh0st源代码详细剖析
  5. 白话科普,10s 了解 API
  6. 第05讲:多路加速,了解多线程基本原理
  7. tomcat源码运行
  8. Linux调度系统全景指南(终结篇)
  9. 五分钟快速理解 Reactor 模型
  10. Redis持久化的几种方式——RDB深入解析