Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created November 9, 2015 09:34
Show Gist options
  • Save sholfen/0f8786db06b8f5e25c5c to your computer and use it in GitHub Desktop.
Save sholfen/0f8786db06b8f5e25c5c to your computer and use it in GitHub Desktop.
for Codility MissingInteger
using System;
namespace MissingInteger
{
class MainClass
{
public static void Main (string[] args)
{
int[] A = { 1, 3, 5, 4, 1, 2 };
int[] B = { 1 };
Solution sol = new Solution ();
int result = sol.solution (B);
Console.WriteLine (result);
}
}
public class Solution
{
public int solution(int[] input)
{
bool[] checkArray = new bool[input.Length + 1];
int result = checkArray.Length;
for (int i = 0; i < input.Length; i++) {
if (input [i] > 0 && input [i] <= input.Length) {
if (!checkArray [input [i]]) {
checkArray [input [i]] = true;
}
}
}
for (int i = 1; i < checkArray.Length; i++) {
if (!checkArray [i]) {
result = i;
break;
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment