diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/125. Valid Palindrome.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/125. Valid Palindrome.py" new file mode 100644 index 00000000..4f54113c --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/125. Valid Palindrome.py" @@ -0,0 +1,30 @@ +''' +1. 아이디어 : +- 문자열을 정제한 후, 정제된 문자열이 회문인지 확인. +2. 시간복잡도 : +o(n) +3. 자료구조/알고리즘 : + +''' +class Solution: + def isPalindrome(self, s: str) -> bool: + small = 'abcdefghijklmnopqrstuvwxyz' + big = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + dic = {} + + for i in range(26): + dic[small[i]] = small[i] + dic[big[i]] = small[i] + + for i in '0123456789': + dic[i] = i + + refined = '' + for i in s: + if i in dic: + refined += dic[i] + + print(refined) + + return refined == refined[::-1] \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/447. Number of Boomerangs.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/447. Number of Boomerangs.py" new file mode 100644 index 00000000..7c1481d3 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/447. Number of Boomerangs.py" @@ -0,0 +1,31 @@ +''' +1. 아이디어 : +- 각 점을 기준으로 다른 점들과의 거리를 계산하고, 같은 거리를 가진 점들의 개수를 세어 부메랑의 수를 계산. +- 이거 원래 3중 for문 돌았는데 그러면 시간초과난다. +2. 시간복잡도 : +o(n^2) +3. 자료구조/알고리즘 : +''' + +from collections import defaultdict +class Solution: + def numberOfBoomerangs(self, points: list[list[int]]) -> int: + n = len(points) + if n < 3: + return 0 + + ans = 0 + for i in range(n): + dic = defaultdict(int) + for j in range(n): + x1,y1 = points[i] + x2,y2 = points[j] + dic[(x2-x1)** 2 + (y2-y1)**2] += 1 + # print(dic) + for value in dic.values(): + if value >= 2: + ans += value * (value -1) + + + return ans + \ No newline at end of file