137. Single Number II
2024-09-28 02:30:16
Given an array of integers, every element appears three times except for one. Find that single one.
代码如下:
public class Solution {
public int singleNumber(int[] nums) {
if(nums.length==1||nums.length==2)
return nums[0];
Arrays.sort(nums);
for(int i=0;i<nums.length-2;)
{
if(nums[i]==nums[i+1]&&nums[i]==nums[i+2])
i=i+3;
else return nums[i];
}
return nums[nums.length-1];
}
}
最新文章
- Java学习笔记1
- Set up Github Pages with Hexo, migrating from Jekyll
- 错误	1	“System.Data.DataRow.DataRow(System.Data.DataRowBuilder)”不可访问,因为它受保护级别限制
- MySQL遇到check the manual that corresponds to your MySQL server version for the right syntax错误
- poj题目必做
- MapReduce 重要组件——Recordreader组件
- ZOJ Problem Set - 3329 One Person Game
- Case swapping
- Python核心编程2第六章课后练习
- 自定义配置文件的使用(web.config/app.config)
- Enum基础
- UVA 11427 - Expect the Expected(概率递归预期)
- [Usaco2008 Nov]Buying Hay 购买干草[背包]
- 20155324王鸣宇 《网络对抗技术》Web基础
- Git——如何将本地项目提交至远程仓库(第一次)
- 搭建redis-sentinel(哨兵机制)集群
- iOS逆向开发(2):获取APP的类声明 | class-dump | dumpdecrypted
- ASP.NET Identity详解
- EZ1105
- 以快板之名说Android 应用程序电源管理
热门文章
- bzoj 1934: [Shoi2007]Vote 善意的投票
- load image
- 企业需要k2来解放孤岛危机
- JAVA学习1
- [网络技术][转]PPTP协议解析
- DataNode,NameNode,JobTracker,TaskTracker用jps查看无法启动解决办法
- C语言:typedef 跟 define 的区别
- 转载--Ubuntu设置环境变量
- mahout中kmeans算法和Canopy算法实现原理
- 多动手试试,其实List类型的变量在页面上取到的值可以直接赋值给一个js的Array数组变量