From 04cd91c90e80d37975d1f388a7082cf89cd0a463 Mon Sep 17 00:00:00 2001 From: ji-hyup Date: Fri, 8 May 2026 12:59:31 +0900 Subject: [PATCH] 08 --- .../06_Count_Commas_in_Range copy.py" | 0 ...istance_Between_Three_Equal_Elements_I.py" | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+) rename "leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range.py" => "leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range copy.py" (100%) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/08_Minimum_Distance_Between_Three_Equal_Elements_I.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range copy.py" similarity index 100% rename from "leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range.py" rename to "leetcode3/\353\263\200\354\247\200\355\230\221/06_Count_Commas_in_Range copy.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/08_Minimum_Distance_Between_Three_Equal_Elements_I.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/08_Minimum_Distance_Between_Three_Equal_Elements_I.py" new file mode 100644 index 00000000..01149d61 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/08_Minimum_Distance_Between_Three_Equal_Elements_I.py" @@ -0,0 +1,33 @@ +''' +1. 아이디어 : + 같은거 찾아서 딕셔너리에 넣고 최소값 구하기. + +2. 시간복잡도 : + O(n) + O(n) + +3. 자료구조/알고리즘 : +''' +from collections import defaultdict + +class Solution: + def minimumDistance(self, nums: List[int]) -> int: + dic = defaultdict(list) + for i in range(len(nums)): + dic[nums[i]].append(i) + + # 0 1 5 10 + + _min = 99999 + + for key, value in dic.items(): + # print(key, value) + + for i in range(len(value) - 2): + a = value[i] + b = value[i+1] + c = value[i+2] + abs_sum = abs(a -b) + abs(b-c) + abs(c-a) + if _min > abs_sum: + _min = abs_sum + + return _min if _min != 99999 else -1 \ No newline at end of file