Given a string input, create a function that will output a compressed version of the string. E.g. Input = "AAABBZZDDD", Output = "A3B2Z2D3"
Sigiloso
- (NSString *)findRunLengthEncoding:(NSString *)givenString { if (givenString.length == 0) //geeksforgeeks //g2e4k2s2f1o1r1 ==> g2e4k2s2f1o1r1 return nil; NSMutableString *returnString = [[NSMutableString alloc] init]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init]; for (int i = 0; i 0) { [returnString appendString:[NSString stringWithFormat:@"%@%@",str, numAppearance]]; } else { if ([numAppearance integerValue] > 0 && [givenString characterAtIndex:i] != [givenString characterAtIndex:i-1]) { [returnString appendString:[NSString stringWithFormat:@"%@%@",str, numAppearance]]; } } [dictionary setObject:@0 forKey:str]; } return [returnString copy]; }