本文共 505 字,大约阅读时间需要 1 分钟。
Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not.
思路:设置两个指针i和j,i指向唯一数组的最后的一个位置,j用于枚举所有元素
void removeDupChar(char* str){ if(str==NULL) return; int i=0,j,k,len=strlen(str); for(j=1;j
下面这个是i=-1,j=0开始的
void removeDupChar(char* str){ if(str==NULL) return; int i=-1,j,k,len=strlen(str); for(j=0;j评:这种思想是在算法导论中快排的时候学到的。
转载地址:http://rfyab.baihongyu.com/