Given an 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?

解题:

此题可直接运用异或运算的性质:N^A^A = N

代码:

 class Solution {
public:
int singleNumber(int A[], int n) {
for (int i = ; i < n; ++i)
A[] ^= A[i];
return A[];
}
};

但是在leetcode网站性能分析中,异或运算(19ms)不是最快的,不知道还有没有其他算法可以达到10ms以下。

【Leetcode】【Medium】Single Number的更多相关文章

  1. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  2. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  3. 【LeetCode题意分析&解答】35. Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  4. ACM金牌选手整理的【LeetCode刷题顺序】

    算法和数据结构知识点图 首先,了解算法和数据结构有哪些知识点,在后面的学习中有 大局观,对学习和刷题十分有帮助. 下面是我花了一天时间花的算法和数据结构的知识结构,大家可以看看. 后面是为大家 精心挑 ...

  5. 【leetcode刷题笔记】Single Number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  6. 【leetcode刷题笔记】Single Number

    题目: Given an array of integers, every element appears twice except for one. Find that single one. No ...

  7. 【LeetCode算法题库】Day3:Reverse Integer & String to Integer (atoi) & Palindrome Number

    [Q7]  把数倒过来 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Outpu ...

  8. 【LeetCode每天一题】Fibonacci Number(斐波那契数列)

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  9. 【leetcode刷题笔记】Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  10. 【leetcode刷题笔记】Excel Sheet Column Number

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

随机推荐

  1. Bound Found(思维+尺取)

    Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...

  2. 对avalonjs的研究

    <!DOCTYPE html> <html> <head> <title>第一个avalon项目</title> <meta char ...

  3. 牌型种数-dfs-蓝桥杯2015

    牌型种数 牌型种数 小明被劫持到 X 赌城,被迫与其他 3 人玩牌. 一副扑克牌(去掉大小王牌,共 52 张),均匀发给 4 个人,每个人 13 张. 这时,小明脑子里突然冒出一个问题: 如果不考虑花 ...

  4. 【研究】ms17-010永恒之蓝漏洞复现

    1       永恒之蓝漏洞复现(ms17-010) 1.1     漏洞描述: Eternalblue通过TCP端口445和139来利用SMBv1和NBT中的远程代码执行漏洞,恶意代码会扫描开放44 ...

  5. idea中使用restclient测试接口发送http请求

    转载:https://jingyan.baidu.com/article/ca41422f0bfd8e1eae99ed31.html

  6. Qt客户端阿里云服上传文件

    整体原理: 阿里云提供了c程序上传文件到阿里云服务器的sdk工具包,将这个工具包继承在自己的客户端,调用接口即可实现上传文件. 前期准备: 1.阿里云c程序客户端的sdk,下载地址:https://h ...

  7. 图解 I帧,B帧以及P帧

    I‑frame (Intra-coded picture): 即完整的一张图片 P‑frame (Predicted picture): 与前面一张图片的区别的区域 B‑frame (Bidirect ...

  8. 2018湖湘杯web、misc记录

    1.题目名 Code Check 打开题目,右键发现有id参数的url,简单base64解码以后发现不是明文,说明利用了其他的加密方式,那么应该会有具体的加密方式给我们,于是试试常见的文件泄露,可以发 ...

  9. 不使用XMLHttpRequest实现异步加载:Iframe和script

    运用Iframe和script可以实现简单的异步加载: 调用页面如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...

  10. sp 数据拼接html table表转换xml,发邮件

    USE [BES_ADV] GO /****** Object: StoredProcedure [dbo].[RSP_FN_UNAPPLIED_Mail_Reminder] Script Date: ...