Check if an array contains only one distinct element | Function to find if the array contains only one distinct element ; Create a set ; Compare and print the result ; Driver code ; Function call
def uniqueElement ( arr , n ) : NEW_LINE INDENT s = set ( arr ) NEW_LINE if ( len ( s ) == 1 ) : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 9 , 9 , 9 , 9 , 9 , 9 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE uniqueElement ( arr , n ) NEW_LINE DEDENT