문제 링크
풀이 과정
전체 코드
def is_win(board, mode):
# 가로 방향
for i in range(3):
count = 0
for j in range(3):
if board[i][j] == mode: count += 1
if count == 3: return True
# 세로 방향
for j in range(3):
count = 0
for i in range(3):
if board[i][j] == mode: count += 1
if count == 3: return True
# 대각선 방향
count = 0
for i, j in zip([0, 1, 2], [0, 1, 2]):
if board[i][j] == mode: count += 1
if count == 3: return True
count = 0
for i, j in zip([2, 1, 0], [0, 1, 2]):
if board[i][j] == mode: count += 1
if count == 3: return True
return False
def solution(board):
answer = 0
x_count, o_count = 0, 0
# 갯수 세기
for i in range(3):
for j in range(3):
if board[i][j] == 'O': o_count += 1
elif board[i][j] == 'X': x_count += 1
if o_count - x_count >= 2: return 0
if x_count > o_count: return 0
if is_win(board, 'O') and is_win(board, 'X'): return 0
if is_win(board, 'O'):
if o_count != x_count + 1: return 0
elif is_win(board, 'X'):
if x_count != o_count: return 0
return 1
Python
복사
유사 문제
•
퍼즐 조각 채우기