Contains Duplicates
Leetcode - 217/219/220 Contains Duplicate - I/II/III 1. Contains Duplicate - I https://leetcode.com/problems/contains-duplicate/ For example given an array [1,2,3,4,1] return true as 1 is repeated , return false all the elements in the array are unique. Solution 1: Brute-Force method - O(n 2 ) time, O(1) space [TLE] While iterating the array check if the element is repeated by comparing it with the rest of elements, if the values compared are equal return true. If the whole the array is traversed that means no element is repeated ,hence return false. bool bruteForce(vector<int>& nums) { ...
Comments
Post a Comment