关闭

LeetCode344. Reverse String

215人阅读 评论(0) 收藏 举报
分类:

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

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


反转字符串

思路:对折交换即可完成

代码如下:

char* reverseString(char* s)
{
    int i;
    char t;
    for(i=0;i<strlen(s)/2;i++)
    {
        t = s[i];
        s[i] = s[strlen(s)-1-i];
        s[strlen(s)-1-i] = t;
    }
    return s;
}


0
0
查看评论

Leetcode344. Reverse String

Description Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”. cppcl...
  • lt2fish
  • lt2fish
  • 2017-06-29 19:13
  • 51

LeetCode344. Reverse String

344. Reverse String My Submissions QuestionEditorial Solution Total Accepted: 6975 Total Submissions: 11764 Difficulty: Easy Write a function that ...
  • liuchuo
  • liuchuo
  • 2016-07-22 01:42
  • 157

leetcode344. Reverse String

344. Reverse StringWrite a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.解法数组中前后进行...
  • rxt2012kc
  • rxt2012kc
  • 2017-03-11 18:47
  • 67

LeetCode344. Reverse String真简单

Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". ...
  • booirror
  • booirror
  • 2016-06-15 13:52
  • 808

reverse a string反转字符串

题目写出一个函数,实现输入一个字符串,返回一个反置字符串。解题过程1.首先考虑用栈的数据结构实现反置。 2.查找java中的栈的结构用法 栈的类Stack没有相应的转置方法。所以放弃使用类 3.使用字符串数组,然后在转成String类型 最初不会开一个char数组,最终经过尝试, char...
  • fegnkuang
  • fegnkuang
  • 2016-05-01 05:44
  • 1754

(LeetCode) Reverse Words in a String

problem :Reverse Words in a String Given an input string, reverse the string word by word. For example, Given s = "the sky is ...
  • zhangyuehuan
  • zhangyuehuan
  • 2014-04-13 09:26
  • 8215

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
  • 1883

[LeetCode]-344. Reverse String(Easy)(C)

344. Reverse String    My Submissions Question Editorial Solution Total Accepted: 11974 Total Submissions: 20496...
  • qq_16542775
  • qq_16542775
  • 2016-05-01 10:22
  • 1573

【LeetCode】Reverse Words in a String III 解题报告

【LeetCode】Reverse Words in a String III 解题报告标签(空格分隔): LeetCode题目地址:https://leetcode.com/problems/reverse-words-in-a-string-iii/#/description题目描述:Given...
  • fuxuemingzhu
  • fuxuemingzhu
  • 2017-04-12 11:48
  • 1104

557. Reverse Words in a String III(C语言)

今天6:30起来,瞌睡了一上午,在柏宁的帮助下把这道反转的题搞出来了嘿嘿char* reverseWords(char* s) { int i=0,j=0; int start=0,end=0; int len=strlen(s); char temp; fo...
  • yanqueen2011
  • yanqueen2011
  • 2017-04-12 10:00
  • 545
    个人资料
    • 访问:50291次
    • 积分:765
    • 等级:
    • 排名:千里之外
    • 原创:42篇
    • 转载:3篇
    • 译文:0篇
    • 评论:2条
    最新评论