Back
Featured image of post My First Blog here

My First Blog here

Leetcode-1486

Hello , This is my first blog here

I’m Minezeratul

今天的每日一题为 1486. 数组异或操作

异或操作 , 即为XOR , 同为0 ,异为1 ,1^0 = 1 0^0 = 0

    public static int xorOperation(int n, int start) {
        if (n == 1) {
            return start;
        }

        int res = 0 ;
        for (int i = 0; i < n; i++) {
            res ^= start + 2 * i;
        }
        return res;
    }

时间复杂度为O(n)

Welcome to the world of Minezeratul