leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 060ee163af4024679c425f7fdd22e552d400c921
parent 7c2b5c79e49bb50b9728c960cd6575c93eb9f71d
Author: AndrewLockVI <andrew.laack@gmail.com>
Date:   Wed,  5 Apr 2023 19:49:28 -0500

Completed first attempt at contains-duplicate question

Diffstat:
Acontains-duplicate/a.out | 0
Acontains-duplicate/contains-duplicate.cpp | 34++++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/contains-duplicate/a.out b/contains-duplicate/a.out Binary files differ. diff --git a/contains-duplicate/contains-duplicate.cpp b/contains-duplicate/contains-duplicate.cpp @@ -0,0 +1,34 @@ +#include <map> +#include <iostream> +#include <vector> +using namespace std; + + +//Leet Ratings +// Speed Memory +//Total 186ms 70.8MB +//Beats 23.71% 29.11% + +// I chose to use maps because I did not know +// that unordered lists exist. I will fix and +// see the difference. I suspect it will be +// margianlly faster and use far less memory. + + +bool containsDuplicate(vector<int>& nums) { + map <int, int> maps; + bool dupe = false; + for(int i = 0; i < nums.size() ; ++i){ + if(maps.find(nums[i])->second){ + dupe = true; + break; + } + maps.insert(pair(nums[i] , 1)); + } + return dupe; +} + +int main(){ +vector<int> input = {0 , 5 , 2, 4, 5 , 8}; +cout << boolalpha << containsDuplicate(input) << endl; +}