题解 | #农场牛的标识# 异或和

农场牛的标识

https://www.nowcoder.com/practice/a9dfab1f870046e4bd829c8a9223f9bc

知识点

异或

思路

由于同一个异或两次为0,所以只要求异或和即能得到只出现一次的数。

时间复杂度 O(n)

AC Code(Python)

from functools import reduce
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param nums int整型一维数组 
# @return int整型
#
class Solution:
    def singleNumber(self , nums: List[int]) -> int:
        return reduce(lambda x, y : x ^ y, nums)

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务