Skip to content

Instantly share code, notes, and snippets.

@mateusmarquezini
Created September 21, 2016 13:46
Show Gist options
  • Save mateusmarquezini/ef47ba1aaa526539f9438ce780b3aabd to your computer and use it in GitHub Desktop.
Save mateusmarquezini/ef47ba1aaa526539f9438ce780b3aabd to your computer and use it in GitHub Desktop.
Codility Distinct problem - Java Solution
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