<문제>
<풀이>
...더보기
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 list = A.ToList();
var count = list.Count + 1;
long listSum = 0;
foreach(var r in list)
{
listSum = r + listSum;
}
var idx = 0;
long totalSum = 0;
long augmenter = 1;
while (idx < count)
{
totalSum = totalSum + (augmenter);
augmenter++;
idx++;
}
return (int)(totalSum - listSum);
}
}
<시간복잡도>
<풀이방법>
1. 1 2 3 5 라고 할 때 1 + 2+ 3+ 4+ 5 = 15가 나온다.
15에서 1 + 2 + 3 + 5 하면 '4' 누락된 숫자가 나온다.
반응형
'프로그래밍 > Codility' 카테고리의 다른 글
[c#] Codility - PermCheck (0) | 2019.09.03 |
---|---|
[c#] codility - TapeEquilibrium - 좀 더 생가해보기. (0) | 2019.09.02 |
[c#] codility : frogjmp (0) | 2019.09.01 |
[c#] Codility - CyclicRotation (0) | 2019.08.30 |
C# [codility] OddOccurrencesInArray (0) | 2019.08.29 |
댓글