Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int frequency(int[] a, int n) {
- int f = 0;
- for (int i = 0; i < a.length; i++) {
- if (a[i] == n) {
- f = f + 1;
- }
- }
- return f;
- }
- int findUniqueElems(int[] a, int[] b) {
- int nu = 0;
- for (int i = 0; i < a.length; i++) {
- if (frequency(a, a[i]) == 1) {
- b[nu] = a[i];
- nu = nu + 1;
- }
- }
- return nu;
- }
- void print(int[] a){
- for (int i = 0; i < a.length; i++) {
- System.out.print(a[i]+ " ");
- }
- }
- int[] copy(int[]a, int l){
- int[] r = new int[l];
- for(int i =0; i < l; i++){
- r[i] = a[i];
- }
- return r;
- }
- int[] unique(int[] a) {
- int[] b = new int[a.length];
- int nu= findUniqueElems(a,b);
- return copy(b,nu);
- }
- int[] a = {32,23,12,23,15,32};
- //System.out.println(frequency(a,127));
- print(unique(a));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement