My LeetCode Journey Day 1

My LeetCode Journey Day 1

One of my New Year's resolutions for 2024, was to sharpen my problem-solving skills. A friend of mine recommended a very impressive tool that categorizes leet code problems, from beginner level, all the way to advanced level. It also groups different leet code problems into their respective data structures. I started off my journey yesterday, solving at least two problems every day using NeetCode.

The first problem I solved was the famous "Identifying a Duplicate". I had to think about the problem carefully and come up with an optimal solution (0n)

here's my approach...

I hope you find this insightful. I dropped comments to explain my thought process.

Thank you for reading

// Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.


// Example 1:

// Input: nums = [1,2,3,1]
// Output: true
// Example 2:

// Input: nums = [1,2,3,4]
// Output: false
// Example 3:

// Input: nums = [1,1,1,3,3,4,3,2,4,2]
// Output: true


var containsDuplicate = function(nums) {
    //create a buffer to store intergers first of

    //create variable to identify unique value
    const set = new Set();

    //I want to loop through the array to check for the duplicate      value
    for(let num of nums) {
        if(set.has(num)) return true

        //here's where we add to the buffer
        set.add(num)
    }
    //return false if nums is not a duplicate
    return false
};


//second solution using the size of the set
var containsDuplicate = function(nums) {
    // create an unordered set then check if the size of the set is equal to the size of the array
    return new Set(nums).size !== nums.length;
};         
Omotola Olatujayan

Fintech | Product Design & Operations Management | Driving User-Centric Innovation | Women in Tech Inclusion Advocate | AI Enthusiastic

1 年

Nice one ????

Peter Abisayo Abiodun

Software engineer | Digital Health Specialist | Java | React | Multimodal Application development | Containerization and Microservices | Relational Databases | Continuous Integration & Deployment

1 年

Haha... Let's go

要查看或添加评论,请登录

Chinaza Adimoha的更多文章

  • Why Tailwind CSS Wasn't Working in My Next.js 15 Project (And How I Fixed It)

    Why Tailwind CSS Wasn't Working in My Next.js 15 Project (And How I Fixed It)

    ?? Next.js 15 + Tailwind CSS Setup Bug & Fix ??? As a Frontend engineer, nothing is more frustrating than a seemingly…

    2 条评论
  • Leetcode Solution To problem 49

    Leetcode Solution To problem 49

    Hello Guys, It's your favorite Agba Coder, Lol. Today I will walk you through my thought process, in solving the…

    4 条评论
  • Flatlist Over ArrayPrototype.map

    Flatlist Over ArrayPrototype.map

    In my Journey of learning and building mobile applications, using React Native and Expo, I have learned a great deal…

    2 条评论

其他会员也浏览了