【Leetcode】Single Number
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?
class Solution {
public:
int singleNumber(int A[], int n) {
int ans = ;
for (int i = ; i < n; ++i) {
ans ^= A[i];
}
return ans;
}
};
异或运算实现。
【Leetcode】Single Number的更多相关文章
- 【LeetCode】Single Number I & II & III
Single Number I : Given an array of integers, every element appears twice except for one. Find that ...
- 【leetcode】Single Number && Single Number II(ORZ 位运算)
题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...
- 【题解】【位操作】【Leetcode】Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【Leetcode】 - Single Number II
Problem Discription: Suppose the array A has n items in which all of the numbers apear 3 times excep ...
- 【leetcode】Single Number II (medium) ★ 自己没做出来....
Given an array of integers, every element appears three times except for one. Find that single one. ...
- 【leetcode】Single Number (Medium) ☆
题目: Given an array of integers, every element appears twice except for one. Find that single one. No ...
- 【leetcode】Single Number II
int singleNumber(int A[], int n) { int once = 0; int twice = 0; int three = 0; for (int i = 0; i < ...
- 【LeetCode】Largest Number 解题报告
[LeetCode]Largest Number 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/largest-number/# ...
- 【LeetCode】792. Number of Matching Subsequences 解题报告(Python)
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
随机推荐
- ABP缓存
简介 缓存是做什么的? 简单的可以认为是一个键值对的数据存于内存中,高速读取.作用为了减少和数据库的交互 Abp中缓存的使用 public class InvoiceAppService : Appl ...
- c# 代码调用ssis包
https://docs.microsoft.com/en-us/sql/integration-services/run-manage-packages-programmatically/loadi ...
- wamp集成环境下mysql数据库的分开部署和远程访问
今天折腾了一天一个小问题,就是明明正确的php代码在访问数据库的时候总是提示DB ERROR.后来才发现是填写数据库名的时候,写成了该数据库的ip地址(其实也是本机ip但是本机还是不能访问),而不是l ...
- docker 笔记(3)第一个dockerfile
#vim Dockerfile FROM ubuntu RUN apt-get update && apt-get install -y vim #docker build -t ub ...
- oracle数据库部分技巧
由于笔者在操作数据库时,遇到几个以前不太常见的操作,感觉有必要记录一下,如下: 1.查被锁表 SELECT object_name, machine, s.sid, s.serial# FROM ...
- 《Android应用性能优化》 第5章 多线程和同步
1.DDMS中可以看见的系统线程(Andorid3.1的Galaxy Tab 10.1为例): main HeapWorker 执行finalize函数和引用对象清理 GC Garbage Colle ...
- Linux_oracle命令大全(转)
Linux_oracle命令大全 一,启动 1.#su - oracle 切换到oracle用户且切换到它的环境 2.$lsnrctl status 查看 ...
- 设置MySQL允许外网访问(转)
设置MySQL允许外网访问 1.修改配置文件sudo vim /etc/mysql/my.cnf把bind-address参数的值改成你的内/外网IP或0.0.0.0,或者直接注释掉这行. 2.登 ...
- eclipse格式化代码模板
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <profi ...
- 2018网络预选赛 徐州H 线段树+树状数组
设读入的数组是a,树状数组用来维护a数组区间和sum,线段树用来维护一个另一个数组ssum的区间和,区间每个点a[i]*(n-i+1),那么l-r的答案是l-r的ssum-(n-r)*(sum[r]- ...