Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
no additional space:void reverse(char str[]){ int i,size = strlen(str); for (i = 0; i < size/2; i++){ str[i] = str[i] ^ str[size - i - 1]; str[size - i - 1] = str[i] ^ str[size - i - 1]; str[i] = str[i] ^ str[size - i - 1]; } return; }
no additional space:
ReplyDeletevoid reverse(char str[]){
int i,size = strlen(str);
for (i = 0; i < size/2; i++){
str[i] = str[i] ^ str[size - i - 1];
str[size - i - 1] = str[i] ^ str[size - i - 1];
str[i] = str[i] ^ str[size - i - 1];
}
return;
}