260. Single Number III
来源:互联网 发布:手机crm软件排名 编辑:程序博客网 时间:2024/03/29 19:29
题目
iven 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].
Note:
The order of the result is not important. So in the above example, [5, 3] is also correct.
Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?
源码
ps:好像不太满足线性的要求,不过提交代码过了。
/** * @param {number[]} nums * @return {number[]} */var singleNumber = function(nums) { var result=[]; if(nums.length==2){ return nums; } nums.sort(); j=0; for(i=0;i<nums.length;i++){ if(nums[i]==nums[i+1]){ i++; } else{ result[j++]=nums[i]; } } return result;};
0 0
- 260.Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- 260. Single Number III
- iOS开发 如何检查内存泄漏
- 项目中必须知道有关css和html的常识
- Android Fragment和FragmentActivity区别和用法
- HDU-3746 Cyclic Nacklace (kmp)
- linux挂载空磁盘步骤
- 260. Single Number III
- 【杭电oj】1509 - Windows Message Queue(优先队列)
- YARN 内存参数终极详解
- JSP Cookie 使用完全详解
- 使用dom4j和jdom解析与生成字符串型XML的代码示例
- UI 设计的整个工作流程是怎样的?
- 蓝桥杯六1奖券数目填空题
- JSP中如何设置Cookies
- android客户端消息推送功能实现方案