Skip to content

Commit 1f8e597

Browse files
Merge pull request #2069 from CodingTestStudy2/최원준
[최원준] Day22
2 parents 300a783 + 7b72c4f commit 1f8e597

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
한칸씩 옮긴다음 계산한다.
6+
7+
2. 시간복잡도 :
8+
O(n**4)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
class Solution:
15+
def largestOverlap(self, img1: list[list[int]], img2: list[list[int]]) -> int:
16+
n = len(img1)
17+
18+
def get_count(offset_x, offset_y):
19+
count = 0
20+
21+
for x in range(n):
22+
for y in range(n):
23+
mx = x + offset_x
24+
my = y + offset_y
25+
if 0<=mx<n and 0<=my<n and img1[x][y] and img2[mx][my]:
26+
count+=1
27+
28+
return count
29+
30+
# def get_count(img1, img2):
31+
# count=0
32+
# for x in range(n):
33+
# for y in range(n):
34+
# if img1[x][y] and img2[x][y]:
35+
# count+=1
36+
# return count
37+
38+
ans = 0
39+
for i in range(-n, n):
40+
for j in range(-n, n):
41+
ans = max(ans, get_count(i, j))
42+
return ans
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
-
6+
7+
2. 시간복잡도 :
8+
O(n)
9+
10+
3. 자료구조/알고리즘 :
11+
dict
12+
13+
'''
14+
class Solution:
15+
def lemonadeChange(self, bills: list[int]) -> bool:
16+
count = {5:0, 10:0, 20:0} #5, 10, 20
17+
18+
def is_possible(payment):
19+
if payment == 20:
20+
if count[10] >= 1 and count[5] >= 1:
21+
count[10] -= 1
22+
count[5] -= 1
23+
count[20] += 1
24+
return True
25+
elif count[10] == 0 and count[5] >= 3:
26+
count[5] -= 3
27+
count[20] += 1
28+
return True
29+
elif payment == 10:
30+
if count[5] >= 1:
31+
count[5] -= 1
32+
count[10] += 1
33+
return True
34+
elif payment == 5:
35+
count[5] += 1
36+
return True
37+
38+
return False
39+
40+
for b in bills:
41+
if not is_possible(b):
42+
return False
43+
return True
44+

0 commit comments

Comments
 (0)