728x90
반응형
1. 숨어있는 숫자의 덧셈 (2)
- 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/120864
- 구현 코드
import re
def solution(my_string):
return sum([int(num) for num in re.findall(r'\d+', my_string)])
2. 안전지대
- 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/120866
- 구현 코드
def solution(board):
n = len(board)
safe_count = 0
for i in range(n):
for j in range(n):
if board[i][j] == 1:
continue
is_safe = True
for x in range(-1, 2):
for y in range(-1, 2):
ni, nj = i + x, j + y
if 0 <= ni < n and 0 <= nj < n and board[ni][nj] == 1:
is_safe = False
break
if is_safe:
safe_count += 1
return safe_count
3. 삼각형의 완성조건 (2)
- 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/120868
- 구현 코드
def solution(sides):
sides.sort()
return len([n1 for n1 in range(sides[1]-sides[0]+1, sides[1]+1)] + [n2 for n2 in range(sides[1]+1, sides[0]+sides[1])])
4. 외계어 사전
- 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/120869
- 구현 코드
from itertools import permutations
def solution(spell, dic):
spell_permutations = set(permutations(spell))
for perm in spell_permutations:
word = ''.join(perm)
if word in dic:
return 1
return 2
728x90
반응형