关闭

leetcode 344 Reverse String

76人阅读 评论(0) 收藏 举报

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

我的解法

public class Solution {
public String reverseString(String s) {
char[] arr = s.toCharArray();
//s.toCharArray() :string 自带的函数,将string格式转化为char数组

for(int i = 0; i< arr.length/2; i++){
char copy = arr[i];
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = copy;
}
s = String.valueOf(arr);
//String.valueOf(arr) :讲arr转化为string
return s;
}
}

0
0
查看评论

leetcode_344 Reverse String

题目分析:对于给定的字符串,执行逆转操作。 解题思路:先统计字符串的长度,然后遍历字符串,将字符串的前后元素一一对调即可实现。 实现程序C++版本class Solution { public: // 字符交换操作 void my_swap(char *s, char *t) ...
  • yzhang6_10
  • yzhang6_10
  • 2016-05-08 18:45
  • 1497

【LeetCode】344. Reverse String 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51416284Subject 出处:https://leetcode.com/problems/reverse-string/ Write a function that t...
  • crazy1235
  • crazy1235
  • 2016-05-15 23:48
  • 11993

344. Reverse String [easy] (Python)

题目链接https://leetcode.com/problems/reverse-string/题目原文 Write a function that takes a string as input and returns the string reversed. Example: ...
  • coder_orz
  • coder_orz
  • 2016-05-07 14:42
  • 1888

LeetCode 344 Reverse String

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". ...
  • gange1992
  • gange1992
  • 2017-04-07 15:43
  • 61

LeetCode 344 Reverse String

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 这道题是蛮...
  • niuooniuoo
  • niuooniuoo
  • 2016-05-01 03:05
  • 475

LeetCode 344:Reverse String

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 编写...
  • judadeshu
  • judadeshu
  • 2016-05-22 21:57
  • 154

LeetCode(344) Reverse String

题目 Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh&qu...
  • fly_yr
  • fly_yr
  • 2016-08-15 22:14
  • 559

[leetcode 344]Reverse String

public class Solution { public String reverseString(String s) { char[] array = s.toCharArray(); StringBuffer sb = new StringBuf...
  • zhjiann_
  • zhjiann_
  • 2016-05-10 00:41
  • 29

[LeetCode]344 Reverse String

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". ...
  • xiaonaughty
  • xiaonaughty
  • 2017-03-06 16:03
  • 104

【LeetCode】344 Reverse String

原题地址:344. Reverse String。解法:string reverseString(string s) { for (int i = 0, j = s.length() - 1; i < j; i++, j--) { char temp = s[i]; ...
  • hlljjy123
  • hlljjy123
  • 2017-04-07 21:19
  • 195
    个人资料
    • 访问:826次
    • 积分:104
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章存档