Skip to content

Commit 0f27fd1

Browse files
committed
125,447
1 parent d0b843d commit 0f27fd1

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
1. 아이디어 :
3+
- 문자열을 정제한 후, 정제된 문자열이 회문인지 확인.
4+
2. 시간복잡도 :
5+
o(n)
6+
3. 자료구조/알고리즘 :
7+
8+
'''
9+
class Solution:
10+
def isPalindrome(self, s: str) -> bool:
11+
small = 'abcdefghijklmnopqrstuvwxyz'
12+
big = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
13+
14+
dic = {}
15+
16+
for i in range(26):
17+
dic[small[i]] = small[i]
18+
dic[big[i]] = small[i]
19+
20+
for i in '0123456789':
21+
dic[i] = i
22+
23+
refined = ''
24+
for i in s:
25+
if i in dic:
26+
refined += dic[i]
27+
28+
print(refined)
29+
30+
return refined == refined[::-1]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
1. 아이디어 :
3+
- 각 점을 기준으로 다른 점들과의 거리를 계산하고, 같은 거리를 가진 점들의 개수를 세어 부메랑의 수를 계산.
4+
- 이거 원래 3중 for문 돌았는데 그러면 시간초과난다.
5+
2. 시간복잡도 :
6+
o(n^2)
7+
3. 자료구조/알고리즘 :
8+
'''
9+
10+
from collections import defaultdict
11+
class Solution:
12+
def numberOfBoomerangs(self, points: list[list[int]]) -> int:
13+
n = len(points)
14+
if n < 3:
15+
return 0
16+
17+
ans = 0
18+
for i in range(n):
19+
dic = defaultdict(int)
20+
for j in range(n):
21+
x1,y1 = points[i]
22+
x2,y2 = points[j]
23+
dic[(x2-x1)** 2 + (y2-y1)**2] += 1
24+
# print(dic)
25+
for value in dic.values():
26+
if value >= 2:
27+
ans += value * (value -1)
28+
29+
30+
return ans
31+

0 commit comments

Comments
 (0)