def missing_number(nums: list) -> int:
i = 1
for n in nums:
if n != i:
return i
i += 1
return i
assert missing_number([2, 3, 4]) == 1
assert missing_number([1, 2, 4]) == 3
assert missing_number([1, 2, 3]) == 4
def missing_number(nums: list) -> int:
return [i for i in range(1,len(nums) +2) if i not in nums][0]
assert missing_number([2, 3, 4]) == 1
assert missing_number([1, 2, 4]) == 3
assert missing_number([1, 2, 3]) == 4
def missing_number(nums: list) -> int:
if nums[0] != 1:
return 1
else:
for i in nums:
if i + 1 not in nums:
return i + 1
assert missing_number([2, 3, 4]) == 1
assert missing_number([1, 2, 4]) == 3
assert missing_number([1, 2, 3]) == 4
public int missingNumber(ArrayList arrayList){
for (int i = 1; i <= arrayList.size()+1; i++) {
if (arrayList.indexOf(i) == -1){
return i;
}
}
return -1;
}
def missing_number(nums: list) -> int:
l = [i+1 for i in range(len(nums) + 1)]
l2 =[i for i in l if i not in nums]
return l2[0]
assert missing_number([2, 3, 4]) == 1
assert missing_number([1, 2, 4]) == 3
assert missing_number([1, 2, 3]) == 4
def missing_number(nums: list) -> int:
num = 1
for i in nums:
if num != i:
return num
num += 1
return num
assert missing_number([2, 3, 4]) == 1
assert missing_number([1, 2, 4]) == 3
assert missing_number([1, 2, 3]) == 4