-1
My teacher gave me this problem but I can’t do it
int solution(int A[], int N);
that, given a matrix A of N integers, returns the smallest positive integer (greater than 0) that does not occur on A.
For example,
- Datum
A = [1, 3, 6, 4, 1, 2], the function must return 5; - For another example, given
A = [1, 2, 3], the function must return 4; - Datum
A = [-1, -3], the function must return 1;
Assume that:
- N is an integer within the range [1.. 100,000];
- Each element of the matrix A is an integer within the range [-1,000,000 ... 1,000,000].
Input matrix elements can be modified.
I tried using the not in list, but I’m having trouble formulating
a =(1, 3, 6, 4, 1, 2)
limite = max(a)
for i in a:
if (i >=0 and i not in a and a <= limite):
b = i;
print(b)
But if you walk
i in a, agrees that it makes no sense to check whetheri not in a, since alwaysiwill be ina? By the way, are you sure this should be in Python? By the given header, it’s more like C.– Woss
Jeez, now that I realize that. will I get to do a tender operation?
– Mazinho95