1486. 数组异或操作

https://leetcode-cn.com/problems/xor-operation-in-an-array/

Java

/*
 * @Author: Goog Tech
 * @Date: 2020-08-15 21:24:49
 * @LastEditTime: 2020-08-15 21:32:09
 * @Description: https://leetcode-cn.com/problems/xor-operation-in-an-array/
 * @FilePath: \leetcode-googtech\#1486. XOR Operation in an Array\Solution.java
 * @WebSite: https://algorithm.show/
 */

/*
 * @lc app=leetcode.cn id=1486 lang=java
 *
 * [1486] 数组异或操作
 */

// @lc code=start
class Solution {
    public int xorOperation(int n, int start) {
        int result = 0;
        for(int i = 0; i < n; i++) {
            result ^= (start + 2 * i);
        }
        return result;
    }
}
// @lc code=end

Python

'''
Author: Goog Tech
Date: 2020-08-15 21:26:33
LastEditTime: 2020-08-15 21:32:16
Description: https://leetcode-cn.com/problems/xor-operation-in-an-array/
FilePath: \leetcode-googtech\#1486. XOR Operation in an Array\Solution.py
WebSite: https://algorithm.show/
'''

#
# @lc app=leetcode.cn id=1486 lang=python
#
# [1486] 数组异或操作
#

# @lc code=start
class Solution(object):
    def xorOperation(self, n, start):
        """
        :type n: int
        :type start: int
        :rtype: int
        """
        result = 0
        for i in range(n): result ^= (start + 2 * i);
        return result
# @lc code=end
Copyright © GoogTech 2021 all right reserved,powered by GitbookLast update time : 2021-09-15 01:55:05

results matching ""

    No results matching ""