This is a memo for myself.

▼ Question

--Enter the bird type numbers (positive integers) that passed in front of you in order in the list. --Returns the most witnessed bird species. --However, if multiple types are witnessed the same number of times, the number of the smallest type is returned.

▼sample input

`python`

```
arr = [1,1,1,4,4,4,5,3]
```

▼sample output

`python`

```
1
```

▼my answer

`python`

```
def migratoryBirds(arr):
x=0
minType=0
#Count the number of each type number
for i in set(arr):
if x<arr.count(i):
x=arr.count(i)
minType=i
#If the number of sightings is the same, give priority to the smaller type number
elif x==arr.count(i):
x=arr.count(i)
if minType>i:
minType=i
return minType
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
arr_count = int(input().strip())
arr = list(map(int, input().rstrip().split()))
result = migratoryBirds(arr)
fptr.write(str(result) + '\n')
fptr.close()
```

** ・ sightings ** Witness (animal) Its id number will be added to your array of sightings.

You would like to be able to find out which type of bird is most common given a list of sightings.

Recommended Posts