给定一个字符串,实现字符串翻转,要求空间复杂度为O(1),时间复杂度为O(n)
==============================================
可以采用与快速排序的思想类似,通过备份一个值不断挖洞来实现翻转
char *from, *to;
while (from < to) {
char t = s[from];
s[from++] = s[to];
s[to--] = t;
}
给定一个字符串,实现字符串翻转,要求空间复杂度为O(1),时间复杂度为O(n)
==============================================
可以采用与快速排序的思想类似,通过备份一个值不断挖洞来实现翻转
char *from, *to;
while (from < to) {
char t = s[from];
s[from++] = s[to];
s[to--] = t;
}