Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions leetcode3/최원준/835. Image Overlap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#

'''
1. 아이디어 :
한칸씩 옮긴다음 계산한다.

2. 시간복잡도 :
O(n**4)

3. 자료구조/알고리즘 :
-

'''
class Solution:
def largestOverlap(self, img1: list[list[int]], img2: list[list[int]]) -> int:
n = len(img1)

def get_count(offset_x, offset_y):
count = 0

for x in range(n):
for y in range(n):
mx = x + offset_x
my = y + offset_y
if 0<=mx<n and 0<=my<n and img1[x][y] and img2[mx][my]:
count+=1

return count

# def get_count(img1, img2):
# count=0
# for x in range(n):
# for y in range(n):
# if img1[x][y] and img2[x][y]:
# count+=1
# return count

ans = 0
for i in range(-n, n):
for j in range(-n, n):
ans = max(ans, get_count(i, j))
return ans
44 changes: 44 additions & 0 deletions leetcode3/최원준/860. Lemonade Change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#

'''
1. 아이디어 :
-

2. 시간복잡도 :
O(n)

3. 자료구조/알고리즘 :
dict

'''
class Solution:
def lemonadeChange(self, bills: list[int]) -> bool:
count = {5:0, 10:0, 20:0} #5, 10, 20

def is_possible(payment):
if payment == 20:
if count[10] >= 1 and count[5] >= 1:
count[10] -= 1
count[5] -= 1
count[20] += 1
return True
elif count[10] == 0 and count[5] >= 3:
count[5] -= 3
count[20] += 1
return True
elif payment == 10:
if count[5] >= 1:
count[5] -= 1
count[10] += 1
return True
elif payment == 5:
count[5] += 1
return True

return False

for b in bills:
if not is_possible(b):
return False
return True

Loading