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

Explore AnimatedOpacity In Flutter

LeetCode — Number of Equivalent Domino Pairs

Perl 6 small stuff #7: Q: How many elements are “AAA”..”ABS”? A: 695 *and* 19!

Acing The AWS Cloud Practioner Certification (CLF-C01)

CLF-C01 AWS Cloud Practioner Exam

My Online Learning Experience At Outbox.

Using Bootstrap to create a student directory

ASSURE INCENTIVES & DAO GOVERNANCE

How internal hackathons can boost your company?

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

ALGORITHM a way to make programs easier

Binary Tree (DFS application)

Leetcode 701. Insert into a Binary Search Tree

Leetcode 2129: Capitalize the Title