码迷,mamicode.com
首页 > 其他好文 > 详细

344-Reverse-String

时间:2016-05-21 01:17:47      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

 

Problem:

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

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

 

One possible Solution:

char* reverseString(char* s) {
    int i,j,k;
    char c;
    k=0;
    while(*(s+k)!=‘\0‘)
       k++;
    for(i=0,j=k-1;i<=j;i++,j++){
             c=*(s+i);
        *(s+i)=*(s+j);
        *(s+j)=c;
    }
    return s;
}

Puzzle:

I have successfully runed the program on my Laptop Computer with gcc4.8.4 in Ubuntu14.04.1 environment. However, the Leetcode website reports "RUNTIME ERROR" 。

Does anyone know the reason?

344-Reverse-String

标签:

原文地址:http://www.cnblogs.com/liutianyi10/p/5513864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!