[leetcode] 217. Contains Duplicate
2016-03-21 14:23
549 查看
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
class Solution { public: bool containsDuplicate(vector<int>& nums) { int n=nums.size(); int i; if(n==0 || n==1) return false; sort(nums.begin(),nums.end()); for(i=0;i<n-1;i++) { if(nums[i]==nums[i+1]) return true; } return false; } };
相关文章推荐
- 【AI】蒙特卡洛搜索树
- [LeetCode][数论]Contains Duplicate
- AIDL的使用
- [置顶] 人工智能实战——人工神经网络(C库iOS交叉编译)
- The working copy "" failed to commit files
- 利用遗传算法求解车辆路径问题
- Infopath——在给form的email地址添加链接打开Outlook
- WaitForTargetFPS和Gfx.WaitForPresent和Graphics.PresentAndSync
- Jenkins进阶系列之——02email-ext邮件通知模板
- Jenkins进阶系列之——01使用email-ext替换Jenkins的默认邮件通知
- 百度地图检索周围小吃添加大头针
- Foxmail 自动备份邮件,自动转发到另外一个邮箱的操作。
- 创建一个中国象棋的阿法狗——阿法象(0)
- Failed to initialize Monitor Thread: Unable to establish loopback connection的错误解决方案
- 503 Service Unavailable是怎么回事
- Mac Mail PGP Setup 如何在苹果电脑上设置安全邮件 良好隐私密码法(英语:Pretty Good Privacy,缩写为PGP)
- 11. Container With Most Water
- {typedir} {style} {tid} {aid} 分别是什么意思?
- 怪异的DetailsView控件的判断问题
- AIDL