【LeetCode】【数组】题号:*442,重复元素出现两次

every blog every motto: You will never know unless you try

0. 前言

1. 正文

1.1 题目

在这里插入图片描述

1.2 题解

python:

class Solution:
    def findDuplicates(self, nums: List[int]) -> List[int]:
        
        res = []
        for i in nums:
            nums[abs(i)-1] *= -1

            if nums[abs(i)-1] >0:
                res.append(abs(i))
        return res

1.3 结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/114805203