aboutsummaryrefslogtreecommitdiff
path: root/contains_duplicate.cpp
blob: 5de86d2c85a485308c53a9f575ad34e7c5c316a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "leetcode.h"

class Solution {
public:
  bool containsDuplicate(vector<int> &nums) {
    bool ans = false;
    for (int i = 0; i < nums.size(); i++)
      for (int j = i + 1; j < nums.size(); j++)
        if (nums[i] == nums[j])
          ans = true;
    return ans;
  }
};

int main() {
  Solution obj;
  vector<int> nums1 = {1, 2, 3, 1}, nums2 = {1, 2, 3, 4},
              nums3 = {1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
  cout << obj.containsDuplicate(nums1) << endl; // expect: 1
  cout << obj.containsDuplicate(nums2) << endl; // expect: 0
  cout << obj.containsDuplicate(nums3) << endl; // expect: 1
}