diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/125. Valid Palindrome.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/125. Valid Palindrome.py" new file mode 100644 index 00000000..d33b46ca --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/125. Valid Palindrome.py" @@ -0,0 +1,20 @@ +# + +''' +1. 아이디어 : + + +2. 시간복잡도 : + O(n) + +3. 자료구조/알고리즘 : + + +''' +class Solution: + def isPalindrome(self, s: str) -> bool: + ans = "" + for c in s: + if c.isalpha() or c.isnumeric(): + ans += c + return ans.lower() == ans[::-1].lower() diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/447. Number of Boomerangs.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/447. Number of Boomerangs.py" new file mode 100644 index 00000000..0f19c6bc --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/447. Number of Boomerangs.py" @@ -0,0 +1,47 @@ +# + +''' +1. 아이디어 : +기준 포인트와 나머지 포인트들의 거리를 구하고 카운트를 한다. +카운트된 갯수(m)중 2개씩 조합한다 m * (m-1) + +2. 시간복잡도 : + O(n * n) + +3. 자료구조/알고리즘 : +hashmap + +''' +class Solution: + def numberOfBoomerangs(self, points: list[list[int]]) -> int: + + def get_distance(p1, p2): + x1, y1 = p1 + x2, y2 = p2 + return (x1-x2)**2 + abs(y1-y2)**2 + + n = len(points) + # distances = [[0 for _ in range(n)] for _ in range(n)] + + # for row in range(n): + # for col in range(n): + # if row == col: continue + # distances[row][col] = get_distance(points[row], points[col]) + + # for a in distances: + # print(a) + + ans = 0 + for mid in points: + distances = defaultdict(int) + + for point in points: + if mid == point: + continue + + distance = get_distance(mid, point) + distances[distance] += 1 + + for _, count in distances.items(): + ans += count * (count-1) + return ans