【LeetCode OJ 136】Single Number
题目链接:https://leetcode.com/problems/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?
解题思路:题意为:给定一个数组。仅仅有一个元素出现了一次。其他元素都出现了两次,找出那个仅仅出现一次的数。
能够遍历数组。分别进行异或运算。
注:异或运算:同样为0,不同为1。遍历并异或的结果就是那个仅仅出现了一次的数。
演示样例代码:
public class Solution
{
public int singleNumber(int[] nums)
{
int result=nums[0];
for (int i = 1; i < nums.length; i++)
{
result^=nums[i];
}
return result;
}
}
【LeetCode OJ 136】Single Number的更多相关文章
- 【LeetCode OJ 268】Missing Number
题目链接:https://leetcode.com/problems/missing-number/ 题目:Given an array containing n distinct numbers t ...
- 【LeetCode算法-9】Palindrome Number
LeetCode第9题 Determine whether an integer is a palindrome. An integer is a palindrome when it reads t ...
- 【Leetcode 136】Single Number
问题描述:给出一个整数数组,除了一个元素外,其他每个元素都出现了2次,找出只出现1次的元素. int singleNumber(vector<int>& nums); 分析:比较自 ...
- 【LeetCode OJ 016】3Sum Closest
题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integ ...
- LeetCode(136) Single Number
题目 Given an array of integers, every element appears twice except for one. Find that single one. Not ...
- 【LeetCode OJ 232】Implement Queue using Stacks
题目链接:https://leetcode.com/problems/implement-queue-using-stacks/ 题目:Implement the following operatio ...
- 【LeetCode OJ 34】Search for a Range
题目链接:https://leetcode.com/problems/search-for-a-range/ 题目:Given a sorted array of integers, find the ...
- 【LeetCode OJ 14】Longest Common Prefix
题目链接:https://leetcode.com/problems/longest-common-prefix/ 题目:Write a function to find the longest co ...
- 【leetcode 字符串处理】Compare Version Numbers
[leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...
随机推荐
- Moon Http Server,强大如斯的全脚本web服务器
Moon Http Server(MHS) 是一个使用Pascal脚本的高性能Web服务器. 昨天晚上是第一次接触.花了30分钟入门,非常强大.是Delphi 者开发Web的福音. 引用一下作者的介绍 ...
- Django day08 多表操作 (一) 多表模型创建
多表模型创建分析:1)作者表:一个作者有姓名和年龄2)作者信息表: 有作者就有信息,点击作者的名字可以查询他的电话和地址, 作者表对应作者信息表,所以他们之间是一对一对的关系3)出版社表: 出版社有对 ...
- 脑洞大开加偏执人格——可持久化treap版的Link Cut Tree2
试了一下先上再下的Treap方式,很高兴,代码变短了,但是,跑的变慢了!!!其实慢得不多,5%左右.而且这个版本的写法不容易写错..只要会一般可持久化Treap的人写着都不难...就是相对于(压行的) ...
- [转]Oracle 存储过程语法
转自:http://www.cnblogs.com/chuncn/archive/2009/04/29/1381282.html 存储过程 1 CREATE OR REPLACE PROCEDURE ...
- 解决emlog默认导航不能修改的问题以及修改后台登录地址的方法
修改默认导航 我们需要使用修改代码的方式来解决 首先找到admin/navbar.php文件 然后找到需要删除的几行代码: if ($type != Navi_Model::navitype_cust ...
- 控制台输入年龄,根据年龄输出不同的提示 ------if……else if ……else 语句
package com.zuoye.test; import java.util.Scanner; public class Nianling { public static void main(St ...
- redis-linux
redis3.0.4 server版本 jedis-2.7.2.jar spring-data-redis-1.6.0.RELEASE.jar commons-pool2-2.3.jar spring ...
- Percona Xtrabackup对数据库进行部分备份
Xtrabackup也可以实现部分备份,即只备份某个或某些指定的数据库或某数据库中的某个或某些表.但要使用此功能,必须启用innodb_file_per_table选项,即每张表保存为一个独立的文件. ...
- (转)基于Metronic的Bootstrap开发框架经验总结(3)--下拉列表Select2插件的使用
http://www.cnblogs.com/wuhuacong/p/4761637.html 在上篇<基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JST ...
- Node.js 常用Mongoose方法
Node.js 手册查询-Mongoose 方法 一.Schema 一种以文件形式存储的数据库模型骨架,无法直接通往数据库端,也就是说它不具备对数据库的操作能力.可以说是数据属性模型(传统意义的表结构 ...