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. Windows XP PRO SP3 - Full ROP calc shellcode

    /*     Shellcode: Windows XP PRO SP3 - Full ROP calc shellcode     Author: b33f (http://www.fuzzysec ...

  2. warning malformed '#pragma pack(push[, id], n)' - ignored

    bmp.c:8: warning: malformed '#pragma pack(push[, id], <n>)' - ignored bmp.c:33: warning: #prag ...

  3. [开发笔记]-js判断用户的浏览设备是移动设备还是PC

    最近做的一个网站页面中需要根据用户的访问设备的不同来显示不同的页面样式,主要是判断移动设备还是电脑浏览器访问的. 下面给出js判断处理代码,以作参考. <script type="te ...

  4. opencv 工程的保存

    一个项目的保存,只要保存工程底下的.CPP  .h   .dll  .lib  输入输出文件即可 最终保存的文件

  5. unix shell-01 file

    1 一个文件有三种访问方式: 1.读,可以显示该文件的内容 2.写,删除或者编辑这个文件 3.执行,如果该文件时一个shell脚本或程序 按照文件所针对的用户,用户可以分为三种: 1.文件属主,即该文 ...

  6. Snagit 12 – 功能强的老牌截图软件

    老牌截图软件 Snagit 12 新版正式发布,相比旧版,Snagit 12 界面变得更加简洁,深色的配色增加了专业感,也更加舒服. 在功能上,Snagit 大幅简化了用户体验,不需要复杂的操作,只需 ...

  7. SharePoint表单和工作流 - Nintex篇(七)

    博客地址 http://blog.csdn.net/foxdave 接上篇点击打开链接 在工作流设计面板点击Close返回到列表页面,切换到List标签,选择"Nintex Forms&qu ...

  8. JavaScript 时间特效 显示当前时间

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. poj1992 数论

    //Accepted 168 KB 969 ms //n!中含有质因数p的个数为t=n/p+n/p^2+n/p^3+... #include <cstdio> #include <c ...

  10. jvm之xms、xmx等参数分析

    注:本文摘自http://www.cnblogs.com/mingforyou/archive/2012/03/03/2378143.html ,感谢原作者 1.参数的含义-vmargs -Xms12 ...