Skip to content

Instantly share code, notes, and snippets.

@dolphinSuPixnet
Last active October 16, 2015 09:59
Show Gist options
  • Save dolphinSuPixnet/687a2ee0d3905342489c to your computer and use it in GitHub Desktop.
Save dolphinSuPixnet/687a2ee0d3905342489c to your computer and use it in GitHub Desktop.
This performance is score 0.
-(int)solution:(NSArray *)A{
int minimum = 0;
for(int i=1; i<A.count; i++){
NSRange range1 = NSMakeRange(0, i);
NSArray *array1 = [A subarrayWithRange:range1];
int sum1 = 0;
for (int j = 0; j<array1.count; j++) {
NSNumber *number = array1[j];
sum1 += number.integerValue;
}
NSRange range2 = NSMakeRange(i, A.count-i);
NSArray *array2 = [A subarrayWithRange:range2];
int sum2 = 0;
for (int j = 0; j<array2.count; j++) {
NSNumber *number = array2[j];
sum2 += number.integerValue;
}
int value = ABS(sum1 - sum2);
if (i == 1) {
minimum = value;
}
minimum = MIN(value, minimum);
}
return minimum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment