Created
November 9, 2015 05:48
-
-
Save sholfen/f983060d32f3f1fb4fcc to your computer and use it in GitHub Desktop.
for Codility FrogRiverOne
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace FrogRiverOne | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] input = { 1, 3, 1, 4, 2, 3, 5, 4 }; | |
Solution sol = new Solution(); | |
int result = sol.solution(5, input); | |
Console.WriteLine("result is:" + result.ToString()); | |
} | |
} | |
class Solution | |
{ | |
public int solution(int x, int[] input) | |
{ | |
bool[] positionCheckArray = new bool[x + 1]; | |
int count = 0; | |
int result = -1; | |
for (int i = 0; i < input.Length; i++) | |
{ | |
if (!positionCheckArray[input[i]]) | |
{ | |
count += 1; | |
positionCheckArray[input[i]] = true; | |
} | |
if (count == x) | |
{ | |
result = i; | |
break; | |
} | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment