Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.

For example:

Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].

代码如下:

 public class Solution {
public int[] singleNumber(int[] nums) {
if(nums.length==2)
return nums; Arrays.sort(nums);
int k=0;
int[]a=new int[2];
for(int i=0;i<nums.length-1;)
{
if(nums[i]==nums[i+1])
i=i+2;
else{
a[k]=nums[i];
i=i+1;
if(k==1)
return a;
else k++;
}
}
a[k]=nums[nums.length-1];
return a;
}
}

260. Single Number III的更多相关文章

  1. leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)

    136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...

  2. leetcode 136 Single Number, 260 Single Number III

    leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...

  3. LeetCode 260. Single Number III(只出现一次的数字 III)

    LeetCode 260. Single Number III(只出现一次的数字 III)

  4. 【刷题-LeeetCode】260. Single Number III

    Single Number III Given an array of numbers nums, in which exactly two elements appear only once and ...

  5. 【一天一道LeetCode】#260. Single Number III

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  6. [LeetCode] 260. Single Number III 单独数 III

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  7. [LeetCode#260]Single Number III

    Problem: Given an array of numbers nums, in which exactly two elements appear only once and all the ...

  8. Java [Leetcode 260]Single Number III

    题目描述: Given an array of numbers nums, in which exactly two elements appear only once and all the oth ...

  9. 【leetcode】260. Single Number III

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

随机推荐

  1. cocopods的使用方法

    虽然网上关于CocoaPods安装教程多不胜数,但是我在安装的过程中还是出现了很多错误,所以大家可以照下来步骤装一下,我相信会很好用. 前言 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正 ...

  2. dedecms5.7安装百度(ueditor)编辑器的方法

    第一步:下载相对应编辑器的版本 第二步:修改inc_func_funcAdmin.php文件 打开include下的inc文件夹内的inc_func_funcAdmin.php找到184行,贴入以下代 ...

  3. HMM TOOL

    HMM隐马尔科夫模型 MATLAB 工具包对各种数据的处理 HMM 工具包下载地址: http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html 工具包使用 ...

  4. [开发笔记]-“在引用COM组件时,出现了无法嵌入互操作类型。。。”的错误

    这两天在做一个需要将wps文档转换成word文档的程序,在调用wps的com组件时项目编译是没有问题的,但当运行的时候却弹出了下面的错误提示: 从网上百度一番后,找到了正确的解决方法. 先从Com组件 ...

  5. IT公司100题-17-第一个只出现一次的字符

    问题描述: 在一个字符串中找到第一个只出现一次的字符.例如输入asdertrtdsaf,输出e.   分析: 最简单的方法是直接遍历,时间复杂度为O(n^2). 进一步思考: 字符串中的字符,只有25 ...

  6. Rhel6-haproxy+keepalived配置文档

    系统环境: rhel6 x86_64 iptables and selinux disabled 主机: 192.168.122.119:haproxy,keepalived server19.exa ...

  7. 宜家的幸福生活,源于K2 BPM的支撑

    很久很久以前,有一篇很火的文章在各大网站被疯狂转载<一个在北欧生活10年的MM,告诉你为什么北欧全球幸福指数第一>,开头第一段就已经让人羡慕嫉妒恨了. "下午的四.五点钟,北欧人 ...

  8. scrollView自动加载数据demo

    package combaidu.mylistsrollview; import java.util.ArrayList;import java.util.List; import com.baidu ...

  9. jquery的监听事件和触发事件

    监听事件 $(selector).on('Event me',function(e){ //do something }) 触发事件 $(selector).trigger('Event name') ...

  10. Properties类与读取properties文件

    Properties类 在Java中,其配置文件常为.properties文件,格式为文本文件,文件的内容的格式是“键=值”的格式,文本注释信息可以用"#"来注释. 这个类的几个常 ...