Find distinct elements Python

PROGRAM TO PRINT ALL DISTINCT ELEMENTS OF A GIVEN INTEGER ARRAY



# This function prints all distinct elements
def printDistinct(arr, n):
      
    # Creates an empty hashset
    s = dict();
  
    # Traverse the input array
    for i in range(n):
          
        # If not present, then put it in
        # hashtable and print it
        if (arr[i] not in s.keys()):
            s[arr[i]] = arr[i];
            print(arr[i], end = " ");
   
# Driver Code
arr = [10, 5, 3, 4, 3, 5, 6];
n = 7;
printDistinct(arr, n);


OUTPUT
10 5 3 4 6 

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java