Exceptionally odd Python

PROGRAM TO FIND THE NUMBER OCCURRING ODD NUMBER OF TIMES



def getOddOccurrence(arr):
 
    # Initialize result
    res = 0
     
    # Traverse the array
    for element in arr:
        # XOR with the result
        res = res ^ element
 
    return res
 
# Test array
arr = [ 2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2]


OUTPUT:
5

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java