Created
September 21, 2016 13:46
-
-
Save mateusmarquezini/ef47ba1aaa526539f9438ce780b3aabd to your computer and use it in GitHub Desktop.
Codility Distinct problem - Java Solution
This file contains 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
import java.util.Arrays; | |
/** | |
* Created by mateus marquezini on 09-09-2016. | |
*/ | |
public class Solution { | |
public int solution(int[] A) { | |
int count = 1; | |
final int fim = A.length - 1; | |
Arrays.sort(A); | |
if (A.length == 0) { | |
return 0; | |
} | |
if (A.length == 1) { | |
return 1; | |
} | |
for (int i = 0; i < A.length - 1; i++) { | |
if (A[i] != A[i + 1]) { | |
count++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment