Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Missing Number problem solution

YASH PAL, 31 July 202421 January 2026

In this Leetcode Missing Number problem solution, we have given an array num containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

Leetcode Missing Number problem solution

Leetcode Missing Number problem solution in Python.

class Solution(object):
    def missingNumber(self, nums):

        L = len(nums)
        final = (1+L)*L/2
        for i in nums:
            final -= i
        return final

Missing Number problem solution in Java.

public int missingNumber(int[] nums) {
        int sum = nums.length * (nums.length + 1) / 2;
        int series = 0;
        for (int num : nums)
            series += num;
        return sum - series;
    }

Problem solution in C++.

class Solution {
public:
    int missingNumber(vector<int>& nums)
    {
        int n=nums.size();
        set<int> s;
        for(int i=0;i<n;i++)
        {
            s.insert(nums[i]);
        }
        for(int i=0;i<=n;i++)
        {
            if(s.find(i)==s.end())
                return i;
        }
        return -1;
    }
};

Problem solution in C.

int missingNumber(int* nums, int numsSize) {
    int *result = calloc(numsSize, sizeof(int));
    for(int i = 0; i < numsSize; i++){
        result[nums[i]] = -1;
    }
    for(int i = 0; i < numsSize; i++){
        if(result[i] >= 0) return i;
    }
    return numsSize;
}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes