Last active
October 16, 2015 09:59
-
-
Save dolphinSuPixnet/687a2ee0d3905342489c to your computer and use it in GitHub Desktop.
This performance is score 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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