260. Single Number III
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的更多相关文章
- leetcode 136. Single Number 、 137. Single Number II 、 260. Single Number III(剑指offer40 数组中只出现一次的数字)
136. Single Number 除了一个数字,其他数字都出现了两遍. 用亦或解决,亦或的特点:1.相同的数结果为0,不同的数结果为1 2.与自己亦或为0,与0亦或为原来的数 class Solu ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- LeetCode 260. Single Number III(只出现一次的数字 III)
LeetCode 260. Single Number III(只出现一次的数字 III)
- 【刷题-LeeetCode】260. Single Number III
Single Number III Given an array of numbers nums, in which exactly two elements appear only once and ...
- 【一天一道LeetCode】#260. Single Number III
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- [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 ...
- [LeetCode#260]Single Number III
Problem: Given an array of numbers nums, in which exactly two elements appear only once and all the ...
- Java [Leetcode 260]Single Number III
题目描述: Given an array of numbers nums, in which exactly two elements appear only once and all the oth ...
- 【leetcode】260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
随机推荐
- 超简单的NDK单步调试方法
令人兴奋的是,ADTr20已经支持JNI单步调试,再也不需要如上这么麻烦的步骤了 你现在需要做的只需以下2步: 1.使用ndk-build编译时,加上如下参数NDK_DEBUG=1,之后生成so文件之 ...
- select2去除搜索框
$("#type_select").select2({ minimumResultsForSearch: -1 });
- 元数据和DbUtils
使用元数据可以在jdbc中获取数据库的定义,例如:数据库.表.列的定义信息. 在jdbc中可以使用: 数据库元数据.参数元数据.结果集元数据. 1.DataBaseMetaData对象 Connect ...
- 如何登录Google美国服务器
Google访问须知: ① 先访问一次 https://www.google.com/ncr ,禁止“国家重定向(No country Redirect) ” ② 再点击右上角齿轮图标,选第一项“Se ...
- Ubuntu根目录下各文件的功能介绍
http://jingyan.baidu.com/article/afd8f4de55189c34e286e9e6.html
- 国产ProcessOn和国外gliffy的对比区别【原创】
之前一直在用国外的作图工具gliffy,不足之处gliffy是英文的,很多国内相关从业者使用起来就有一定门槛,今天我给大家再推荐一款比gliffy更方便的作图工具ProcessOn,除了绘制UML建模 ...
- new work
果不其然,还是电子工程师适合我.
- 补码复习的好例子---Int范围的科学解释
Int范围的科学解释 这得从二进制的原码说起: 如果以最高位为符号位,二进制原码最大为0111111111111111=2的15次方减1=32767 最小为1111111111111111=-2的15 ...
- MySQL中like的使用方法
Like的运用场合主要在模糊查询的时候,一般以查询字符串居多,这里据一些例子来说他的一般用法: <1>查询name字段中包含有“明”字的:例 select * from table1 wh ...
- 三极管的妙用之C118自动刷机
首先咱们要搞清楚咱们自动刷机的原理,不谈修改固件那么高深的东西,简单的就是控制开机键. 使用继电器来控制基本上算是上个世纪的想法吧,之前博主也做过,做出来的感觉其实也很不错,就像是一个收藏品.因为继电 ...