Skip to content

Instantly share code, notes, and snippets.

@neo125874
Created July 22, 2016 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neo125874/18997b083f2ae61ddad5de1be5ed4479 to your computer and use it in GitHub Desktop.
Save neo125874/18997b083f2ae61ddad5de1be5ed4479 to your computer and use it in GitHub Desktop.
Codility Lesson 3-1 Time Complexity
using System;
using System.Linq;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(int[] A) {
var totalSum = A.ToList().Sum();
var minDif = int.MaxValue;
var prevSum = 0;
for (int i = 0; i < A.Length-1; i++)
{
prevSum += A[i];
var rest = totalSum - prevSum;
var dif = Math.Abs(prevSum - rest);
minDif = dif < minDif ? dif : minDif;
}
return minDif;
// write your code in C# 6.0 with .NET 4.5 (Mono)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment