344-Reverse-String
Posted Lee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了344-Reverse-String相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章