美文网首页
算法案例20

算法案例20

作者: 奔跑的蜗牛最开心 | 来源:发表于2019-12-24 18:22 被阅读0次

1.假设有一个字符串aabcad,请写一段程序,去掉字符串中不相邻的重复字符串,即上述字符串处理之后的输出结果为:aabcd

NSMutableString * str = [[NSMutableString alloc]initWithFormat;@“aabcad”];

for (int i = 0 ,i < str.length - 1 ;i++){

unsigned char a = [str characterAtIndex:i];

for (int j = i + 1 ,j < str.length ,j++){

    unsigned char b = [str characterAtIndex:j];

    if (a == b ){

        if (j == i + 1){

            }else{

            [str deleteCharactersInRange:NSMakeRange(j, 1)];

            }

        }

    }

}

NSLog(@“%@”,str);

相关文章

网友评论

      本文标题:算法案例20

      本文链接:https://www.haomeiwen.com/subject/rxvfoctx.html