Answers for "Write a function that given an array A of N integers, returns the smallest integer greater than 0 that does not occur in A."

1

Write a function that given an array A of N integers, returns the smallest integer greater than 0 that does not occur in A.

using System;
// you can also use other imports, for example:
// using System.Collections.Generic;

// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");

class Solution
{
    public int solution(int[] A)
    {
        // write your code in C# 6.0 with .NET 4.5 (Mono)
        int n = 1;
        Array.Sort(A);
        for (int i = 1; i <= 100000; i++)
        {
            for (int i2 = 0; i2 <= A.Length - 1; i2++)
            {
                if (A[i2] == i)

                {
                    n = A[i2] + 1;
                    break;
                }

            }



        }
        return n;

    }
}
Posted by: Guest on September-28-2021

Code answers related to "Write a function that given an array A of N integers, returns the smallest integer greater than 0 that does not occur in A."

Browse Popular Code Answers by Language