반응형
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
- 다익스트라
- 다이나믹 프로그래밍
- 그리디
- level1
- 스택
- BOJ
- 백준
- 수학
- 에라스토테네스의 체
- 가상메모리
- 운영체제
- MYSQL
- 딕셔너리
- BFS
- DP
- 파이썬
- 투포인터
- 가상메모리 관리
- 힙
- 코딩테스트
- level2
- 브루트포스
- N과M
- 프로그래머스
- 재귀
- 구현
- level3
- python
- dfs
- programmers
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 |