binary code, binary, binary system-475664.jpg
0 0
Read Time:39 Second

find the lonely integer from the array of integer

#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'lonelyinteger' function below.
#
# The function is expected to return an INTEGER.
# The function accepts INTEGER_ARRAY a as parameter.
#

def lonelyinteger(a):
    match=[0] * len(a)
    for i in range(0,len(a)):
        for j in range(0,len(a)): 
            if i!=j:
                if a[i]==a[j]:
                    match[i]+=1
    for x in range(0,len(match)):
        if match[x]==0:
            return a[x]

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())

    a = list(map(int, input().rstrip().split()))

    result = lonelyinteger(a)

    fptr.write(str(result) + '\n')

    fptr.close()
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

One thought on “Lonely Integer

Leave a Reply

Your email address will not be published. Required fields are marked *