字符串翻转问题

来源:互联网 发布:mac os 个版本代号 编辑:程序博客网 时间:2024/06/07 13:31

给定一个字符串,实现字符串翻转,要求空间复杂度为O(1),时间复杂度为O(n)

==============================================

可以采用与快速排序的思想类似,通过备份一个值不断挖洞来实现翻转

char *from, *to;while (from < to) {    char t = s[from];    s[from++] = s[to];    s[to--] = t;}
0 0
原创粉丝点击