首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【LeetCode每日打卡】136. Single Number

【LeetCode每日打卡】136. Single Number

作者头像
韩旭051
发布于 2020-06-23 10:45:34
发布于 2020-06-23 10:45:34
5620
举报
文章被收录于专栏:刷题笔记刷题笔记

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1:

Input: [2,2,1] Output: 1 Example 2:

Input: [4,1,2,1,2] Output: 4

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/single-number 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

经典位运算题目

JAVA

代码语言:javascript
复制
class Solution {
    public int singleNumber(int[] nums) {
        for(int i=1;i<nums.length;i++)
            nums[i] ^= nums[i-1];
        return nums[nums.length-1];
    }
}

早睡早起 身体好

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/14 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 经典位运算题目
  • JAVA
  • 早睡早起 身体好
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档