프로그래머스
def solution(n, lost, reserve):
answer = 0
temp = []
for i in range(len(lost)):
if lost[i] in reserve:
temp.append(lost[i])
for num in temp:
lost.remove(num)
reserve.remove(num)
for i in range(len(reserve)):
num1 = reserve[i]-1
num2 = reserve[i]+1
if num1 in lost:
lost.remove(num1)
continue
if num2 in lost:
lost.remove(num2)
continue
answer = n-len(lost)
return answer
import itertools
def isPrime(arr, num):
return arr[num]
def solution(numbers):
answer = 0
number_list = []
ans = []
for num in numbers:
number_list.append(num)
n = len(number_list)
for i in range(1, n+1):
combi = list(set(map(int, map("".join, itertools.permutations(number_list, i)))))
ans += combi
ans = list(set(ans))
n=max(ans)
arr = [False,False] + [True]*(n-1)
primes=[]
for i in range(2,n+1):
if arr[i]:
primes.append(i)
for j in range(2*i, n+1, i):
arr[j] = False
for test in ans:
if isPrime(arr, test):
answer += 1
return answer
def solution(brown, yellow):
blocks = brown+yellow
for col in range(3, blocks):
if blocks % col == 0:
row = blocks // col
if (row-2)*(col-2) == yellow:
answer = [row, col]
break
return answer
def solution(routes):
answer = 1
routes.sort(key = lambda x:x[1])
check = [False] * len(routes)
idx = 1
camera = routes[0][1]
for i in range(len(routes)):
if check[i] == False:
if routes[i][0] <= camera <= routes[i][1]:
check[i] = True
else:
camera = routes[i][1]
answer += 1
check[i] = True
return answer