- (void)viewDidLoad {
[super viewDidLoad];
NSString *oneString = @"dfjkbnlskbanvjkfnb";
NSString *twoString = @"vkjbnkdfdsfknbg ";
NSLog(@"oneString====> %@ \n twoString====> %@ ",oneString,twoString);
NSString *maxString = oneString;
NSString *smallString = twoString;
if (oneString.length < twoString.length) {
maxString = twoString;
smallString = oneString;
}
[self findMaxSubString:maxString smallString:smallString];
}
- (void)findMaxSubString:(NSString *)maxString smallString:(NSString *)smallString {
NSString *printSubString = @"";
for (int i = 0; i <smallString.length; i++) {
NSString *str = [smallString substringWithRange:NSMakeRange(i, 1)];
if ([maxString containsString:str] && ![printSubString containsString:str]) {
printSubString = [printSubString stringByAppendingString:str];
}
}
NSLog(@"printSubString====> %@",printSubString);
}
网友评论