2021-03-09:找出数组中与其他元素不同的元素

找出数组中与其他元素不同的元素

There is an array with some numbers. All numbers are equal except for one. Try to find it!

find_uniq([1,1,1,2,1,1])==2find_uniq([0,0,0.55,0,0])==0.55

It’s guaranteed that array contains at least 3 numbers.

The tests contain some very huge arrays, so think about performance.

This is the first kata in series:

Find the unique number (this kata)

Find the unique string

Find The Unique

---------------------------------------------------------------------------------------------------------------------------------------------

answer:

def find_uniq(arr):

    # your code here

    n=0

    for i in arr:

        if arr.count(i) ==1:

            n=n+i

    return n  # n: unique integer in the array

你可能感兴趣的:(2021-03-09:找出数组中与其他元素不同的元素)