數組中重復的數字 -python


思路:題目比較簡單,之間遍歷一遍數組,不存在的話將這個值放入列表,否則輸出這個值

# -*- coding:utf-8 -*-
class Solution:
    # 這里要特別注意~找到任意重復的一個值並賦值到duplication[0]
    # 函數返回True/False
    def duplicate(self, numbers, duplication):
        # write code here
        lists = []
        for i in numbers:
            if i not in lists:
                lists.append(i)
            else:
                duplication[0] = i
                return True
        return False


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM