Java Number Negate negate(int[] x, int Max)

Here you can find the source of negate(int[] x, int Max)

Description

output all integers from the range [0,Max) that are not in the array

License

Apache License

Declaration

static int[] negate(int[] x, int Max) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*ww w .  ja va  2s . co m*/
    * output all integers from the range [0,Max) that are not
    * in the array
    */
    static int[] negate(int[] x, int Max) {
        int[] ans = new int[Max - x.length];
        int i = 0;
        int c = 0;
        for (int j = 0; j < x.length; ++j) {
            int v = x[j];
            for (; i < v; ++i)
                ans[c++] = i;
            ++i;
        }
        while (c < ans.length)
            ans[c++] = i++;
        return ans;
    }
}

Related

  1. negate(double[] output, double[] a)
  2. negate(double[] values)
  3. negate(final Boolean bool)
  4. negate(int[] ar)
  5. negate(int[] input)
  6. negate(String expr)
  7. negate(String string, String trueValue, String falseValue)
  8. negate(String value)
  9. negateExact(double a)