소프트웨어에 대한 모든 것

LeetCode 풀기 - 1200. Minimum Absolute Difference 본문

알고리즘/LeetCode

LeetCode 풀기 - 1200. Minimum Absolute Difference

앤테바 2021. 12. 21. 08:01
반응형

1200. Minimum Absolute Difference

https://leetcode.com/problems/minimum-absolute-difference/

 

Minimum Absolute Difference - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

문제)

솔루션1) Easy one path

class Solution(object):
    def minimumAbsDifference(self, arr):
        """
        :type arr: List[int]
        :rtype: List[List[int]]
        """
        arr.sort()
        d = {}
        for i in range(len(arr)-1):
            diff = abs(arr[i+1]-arr[i])
            if diff in d:
                d[diff].append([arr[i],arr[i+1]])
            else:
                d[diff] = [[arr[i],arr[i+1]]]
        return d[min(d.keys())]

 

반응형
Comments