Leet Code OJ 136. Single Number
2016-02-26 11:56
423 查看
题目:
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?
代码实现1:
代码实现2:
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?
代码实现1:
[code]public class Solution { public int singleNumber(int[] nums) { int res=0; for(int i=0;i<nums.length;i++){ res=res^nums[i]; } return res; } }
代码实现2:
[code]public class Solution { public int singleNumber(int[] nums) { int target; for(int i=0;i<nums.length;i++){ target=nums[i]; boolean found=false; for(int j=0;j<nums.length;j++){ if(target==nums[j]&&i!=j){ found=true; break; } } if(found==false){ return target; } } return 0; } }
相关文章推荐
- Java并发编程(一)
- form 表的post提交,其中一个超多数据的input标签在后台获取数据被截断的解决方法
- iOS开发解决UITableViewCell和添加侧滑手势冲突的问题
- 单元测试
- 向scrapy中的spider传递参数的几种方法
- Android 判断 PendingIntent 是否存在
- Java使用zip4j进行压缩文件处理
- 自定义日期选择Dialog显示位置
- 【回忆的沙漏——半年总结】
- 网络视频解决方案
- P2P的理解
- PHPExcel导入导出Excel文件
- 震动
- jquery datetimepicker 时间选择控件
- iOS项目不支持横屏的前提下某个界面横竖屏(旋转)的解决方案
- 【leetcode】Array——Search in Rotated Sorted Array II(81)
- 使用补丁修改DSDT/SSDT [DSDT/SSDT综合教程]
- Swift编程之枚举类型详解
- SpringMVC的各种参数绑定方式
- ScrollView跳至前一个或者指定位置