문제: app.codility.com/programmers/lessons/3-time_complexity/tape_equilibrium/
if (A.Length >= 2 && A.Length <= 100000)
{
int sum1 = 0;
int sum2 = 0;
for (int i = 0; i < A.Length; i++)
{
if (i == 0)
sum1 = A[i];
else
sum2 = sum2 + A[i];
}
int result = Math.Abs(sum1 - sum2);
for (int i = 2; i < A.Length; i++)
{
sum1 = sum1 + A[i - 1];
sum2 = sum2 - A[i - 1];
if (result > Math.Abs(sum1 - sum2))
result = Math.Abs(sum1 - sum2);
}
return result;
}
return 0;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson4. MaxCounters (C#) (0) | 2020.11.17 |
---|---|
[Codility] Lesson4. FrogRiverOne (C#) (0) | 2020.11.17 |
[Codility] Lesson3. PermMissingElem (C#) (0) | 2020.11.17 |
[Codility] Lesson3. FrogJmp (C#) (0) | 2020.11.17 |
[Codility] Lesson2. CyclicRotation (C#) (0) | 2020.11.17 |