排序并压缩字符串
将字符串中的字符串按照ASCII从小到大的顺序排序,然后压缩
压缩策略是将连续出现的字符转换成字符+次数的形式
如传入:@"Lifeislikeridingabicycletokeepyourblanceyoumustkeepmoving"
排序后(5分):@"Laabbcccdeeeeeeeefggiiiiiiikkklllmmnnnoooopprrssttuuuvyyy"
压缩后(10分):
@"La2b2c3de8fg2i7k3l3m2n3o4p2r2s2t2u3vy3"
*/
将字符串中的字符串按照ASCII从小到大的顺序排序,然后压缩
压缩策略是将连续出现的字符转换成字符+次数的形式
如传入:@"Lifeislikeridingabicycletokeepyourblanceyoumustkeepmoving"
排序后(5分):@"Laabbcccdeeeeeeeefggiiiiiiikkklllmmnnnoooopprrssttuuuvyyy"
压缩后(10分):
@"La2b2c3de8fg2i7k3l3m2n3o4p2r2s2t2u3vy3"
*/
-(NSString *)sortAndCompress:(NSString *)string{
//const char *p = [string UTF8String];
//首先把不可变字符串转化为可变字符串,因为可变字符串有替换操作
NSMutableString *muString = [NSMutableString stringWithString:string];
//进行排序,冒泡,升序
//NSLog(@"%lu",string.length);
for (int i = 0; i < muString.length - 1; i++) {
for (int j = 0 ; j < muString.length - i - 1;