관리자

https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/submissions/

class Solution: 
    def findDisappearedNumbers(self, nums: List[int]) -> List[int]: 
        for i in range(len(nums)): 
            c = 0 
            while nums[i] != nums[nums[i]-1] and nums[i] != i+1 : 
                if c > 4: break 
                print(nums, nums[i], nums[nums[i]-1])
                # right
                nums[i], nums[nums[i]-1] = nums[nums[i]-1], nums[i] 
                # wrong
                #nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1] 
                c+=1 

'언어 > python cheatsheet' 카테고리의 다른 글

remove key from dictionary if exists, else return None  (0) 2019.10.23
dictionary comprehension  (0) 2019.10.22
zip()  (0) 2019.10.22
string replace with dictionary mapping(maketrans, translate)  (0) 2019.10.22
원소 수세기 : Counter  (0) 2019.10.08

+ Recent posts