Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- BFS
- 프로그래머스
- 코딩테스트
- programmers
- 가상메모리
- 스택
- dict
- 다이나믹 프로그래밍
- level0
- 그리디
- 가상메모리 관리
- level2
- dfs
- 브루트포스
- 다익스트라
- 재귀
- level1
- 힙
- N과M
- 딕셔너리
- 백준
- BOJ
- 운영체제
- MYSQL
- 파이썬
- python
- 수학
- level3
- DP
- 구현
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level0 [안전지대] 파이썬 본문
https://school.programmers.co.kr/learn/courses/30/lessons/120866
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
# 프로그래머스 안전지대
r = [1, 1, 1, 0, -1, -1, -1, 0]
c = [-1, 0, 1, 1, 1, 0, -1, -1]
def solution(board):
answer = 0
n = len(board)
for i in range(n):
for j in range(n):
if board[i][j] == 1:
for k in range(8):
I = r[k]+i
J = c[k]+j
if 0 <= I < n and 0 <= J < n and board[I][J] != 1:
board[I][J] += 2
for line in board:
answer += line.count(0)
return answer
bfs탐색하듯이 코드를 만들면된다. (단 bfs처럼 계속 탐색은 안함)
'코테 > 프로그래머스 level0' 카테고리의 다른 글
프로그래머스 level0 [분수의 덧셈] 파이썬 (0) | 2023.03.05 |
---|---|
프로그래머스 level0 [연속된 수의 합] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [겹치는 선분의 길이] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [평행] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [숫자 찾기] 파이썬 (0) | 2023.03.05 |