Created
November 9, 2015 09:34
-
-
Save sholfen/0f8786db06b8f5e25c5c to your computer and use it in GitHub Desktop.
for Codility MissingInteger
This file contains hidden or 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
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