[LeedCode OJ]#137 Single Number II
2015-08-24 20:32
411 查看
【 声明:版权所有,转载请标明出处,请勿用于商业用途。 联系信箱:libin493073668@sina.com】
题目链接:https://leetcode.com/problems/single-number-ii/
题意:
数组内除了一个数之外其他数都出现了三次,找到这个只出现了一次的数
思路:
排好序之后,三个一组的进行判断
题目链接:https://leetcode.com/problems/single-number-ii/
题意:
数组内除了一个数之外其他数都出现了三次,找到这个只出现了一次的数
思路:
排好序之后,三个一组的进行判断
class Solution { public: int singleNumber(vector<int>& nums) { int len = nums.size(); int i,j; sort(nums.begin(),nums.end()); for(i = 0; i<len;) { if(nums[i]==nums[i+1]&&nums[i+1]==nums[i+2]) { i+=3; continue; } return nums[i]; } return nums[len-1]; } };
相关文章推荐
- Can you solve this equation?--二分
- Introduction to Java Programming编程题9.4<求某个字符的出现次数>
- 回调函数
- JFreeChart的基本使用
- Linux格式化硬盘 常用命令小记
- 2015/8/24/checkBox/imageView/ArrayAdapter/SimpleAdapter/自定义Adapter
- 我的潜意识
- python 模块学习--Numpy
- HDU 1695 GCD(容斥定理)
- 集线,路由和交换的概念
- 迷茫
- SQL函数
- C++实现String
- Android第四讲——常用的基本控件(一)TextView、EditText、Button、RadioButton、CheckButton、ImageView
- Android开发学习笔记:Intent的简介以及属性的详解
- ftk学习记录(脚本文章)
- Design Pattern_Java:Builder Pattern
- UIView常用的方法
- 解决传中文参数乱码的问题
- poj 2965 The Pilots Brothers' refrigerator