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 /*************************************************************************
 2     > File Name: LeetCode344.c
 3     > Author: Juntaran
 4     > Mail: [email protected]
 5     > Created Time: 2016年05月10日 星期二 02时25分37秒
 6  ************************************************************************/
 7
 8 /*************************************************************************
 9
10     Reverse String
11
12     Write a function that takes a string as input and returns the string reversed.
13
14     Example:
15     Given s = "hello", return "olleh".
16
17  ************************************************************************/
18
19 #include "stdio.h"
20
21 char* reverseString(char* s)
22 {
23     int i;
24     int length = strlen(s);
25     char temp;
26
27     for( i=0; i<length/2; i++ )
28     {
29         temp = s[i];
30         s[i] = s[length-i-1];
31         s[length-i-1] = temp;
32     }
33     return s;
34 }
35
36 int main()
37 {
38     char* s = "hello";
39     reverseString(s);
40     return 0;
41 }
时间: 2024-07-30 20:32:04

LeetCode 344的相关文章

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

Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place wit

[LeetCode] 344 Reverse String &amp; 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 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) {        

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 class Solution { 2 public: 3 string reverseString(string s) { 4 int i = 0 ; 5 int j = s.size()-1; 6 while(i<

Python [Leetcode 344]Reverse String

题目描述: Write a function that takes a string as input and returns the string reversed. Example:Given s = "hello", return "olleh". 解题思路: 见代码. 代码如下: class Solution(object): def reverseString(self, s): """ :type s: str :rtype

python(leetcode)-344反转字符串

编写一个函数,其作用是将输入的字符串反转过来.输入字符串以字符数组 char[] 的形式给出. 不要给另外的数组分配额外的空间,你必须原地修改输入数组.使用 O(1) 的额外空间解决这一问题. 你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符. 示例 1: 输入:["h","e","l","l","o"] 输出:["o","l","l"

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

------------------------------- Java也可以实现一行代码反转字符串哦 AC代码如下: public class Solution { public String reverseString(String s) { return new StringBuffer(s).reverse().toString(); } } 题目来源: https://leetcode.com/problems/reverse-string/

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