[LeetCode]#645. Set Mismatch

Input: nums = [1,2,2,4]
Output: [2,3]
class Solution:
def findErrorNums(self, nums):
dic={}
for i in range(1,len(nums)+1):
dic[i]=0
for n in nums:
dic[n]+=1
d1=list(dic.values()).index(2)
f1=d1+1
d2=list(dic.values()).index(0)
f2=d2+1
return[f1,f2]

--

--

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
Fatboy Slim

Fatboy Slim

Interesting in any computer science.