<easy>LeetCode Problem -- 217. Contains Duplicate
2018-02-03 18:12
489 查看
描述: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) { if (nums.empty()) return false; sort(nums.begin(), nums.end()); for (int i = 1; i < nums.size(); i++) { if (nums[i] == nums[i - 1]) return true; } return false; } };
相关文章推荐
- <easy>LeetCode Problem -- 283. Move Zeroes
- <easy>LeetCode Problem -- 404. Sum of Left Leaves
- <easy>LeetCode Problem -- 674. Longest Continuous Increasing Subsequence
- <easy>LeetCode Problem -- 268. Missing Number
- <easy>LeetCode Problem -- 617. Merge Two Binary Trees
- <easy>LeetCode Problem -- 566. Reshape the Matrix
- <easy>LeetCode Problem -- 27. Remove Element
- <easy>LeetCode Problem -- 766. Toeplitz Matrix
- <easy>LeetCode Problem -- 448. Find All Numbers Disappeared in an Array
- <easy>LeetCode Problem -- 669. Trim a Binary Search Tree
- <easy>LeetCode Problem -- 637. Average of Levels in Binary Tree
- <easy>LeetCode Problem -- 563. Binary Tree Tilt
- <easy>LeetCode Problem -- 606. Construct String from Binary Tree
- <easy>LeetCode Problem -- 219. Contains Duplicate II
- <easy>LeetCode Problem -- 561. Array Partition I
- <easy>LeetCode Problem -- 661. Image Smoother
- <easy>LeetCode Problem -- 655. Print Binary Tree
- <easy>LeetCode Problem -- 695. Max Area of Island
- <easy>LeetCode Problem -- 653. Two Sum IV - Input is a BST
- <medium> Leetcode Problem -- 654. Maximum Binary Tree