#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019-08-13 22:35 # @Author : daryl # @File : main.py def use_map(numbers): """ 使用哈希表結構 :param numbers: :return: """ num_map = dict() for number in numbers: if number in num_map: print(number) else: num_map[number] = True def use_set(numbers): """ 使用set結構 :param numbers: :return: """ num_set = set() for number in numbers: if number in num_set: print(number) else: num_set.add(number) def use_sort(numbers): """ 排序後查找 :param numbers: :return: """ numbers = sorted(numbers) print(numbers) for index, number in enumerate(numbers): if index != number: continue if number == numbers[number]: print(number) else: numbers[index], numbers[number] = numbers[number], numbers[index] if __name__ == '__main__': numbers = [2, 3, 1, 0, 2, 5, 3] # use_map(numbers) # use_set(numbers) use_sort(numbers)