Find All Numbers Disappeared in an Array

Input: nums = [4,3,2,7,8,2,3,1]
Output: [5,6]
Input: nums = [1,1]
Output: [2]
  • n == nums.length
  • 1 <= n <= 105
  • 1 <= nums[i] <= n
class Solution:
def findDisappearedNumbers(self, nums):
result=[]
n=len(nums)
for i in range(1,n+1):
found=False
for j in nums:
if i==j:
found=True
break
if(not found):
result.append(i)

return li
class Solution:
def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
li=[]
for i in range(len(nums)):
temp=nums[i]-1
if(temp>=0):
while(nums[temp]>0):
val=nums[temp]-1
nums[temp]=0
temp=val
for i in range(len(nums)):
if(nums[i]!=0):
li.append(i+1)

return li

def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
result=[]

for i in nums:
index=abs(i)-1
nums[index]= -1*abs(nums[index])
for i in range(len(nums)):
if(nums[i]>0):
result.append(i+1)
return result

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Java Series: Basics Q&A Part 7

Hosting Python package in Azure Devops

Hiring an App Developer/Web Developer

i.MX8MP Compiles DPDK Source Code to Realize rte_ring Lock-free Ring Queue Inter-process…

Plan, build, and ship better products with Live Apps in Quip

A Greedy Algorithm for Personal Growth

Building Apps is for Dinosaurs 🦖

How to Architect IOT Based Applications

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

Algorithms

Knight Probability in Chessboard Solution | LeetCode-688: Medium | JavaScript Implementation

What is a Queue?

Leetcode 452. Minimum Number of Arrows to Burst Balloons