- (NSArray)pascal:(int)n { if (n == 1) return @[@(1)];
NSArray array = [self pascal:n-1]; NSMutableArray* mArray = [@[] mutableCopy]; for(int i = 0; i < array.count+1; i++) { int r = i - 1; if (r >= 0 && i < array.count) [mArray addObject:@([array[r] integerValue] + [array[i] integerValue])]; else if (i < array.count) [mArray addObject:@(0 + [array[i] integerValue])]; else [mArray addObject:@(0 + [array[i-1] integerValue])]; }
return [mArray copy]; }
- (NSArray)pascal:(int)n { if (n == 1) return @[@(1)];
NSArray array = [self pascal:n-1]; NSMutableArray* mArray = [@[] mutableCopy]; for(int i = 0; i < array.count+1; i++) { int r = i - 1; if (r >= 0 && i < array.count) [mArray addObject:@([array[r] integerValue] + [array[i] integerValue])]; else if (i < array.count) [mArray addObject:@(0 + [array[i] integerValue])]; else [mArray addObject:@(0 + [array[i-1] integerValue])]; }
return [mArray copy]; }