336. 순위

아현·2021년 11월 12일
0

Algorithm

목록 보기
360/400
post-custom-banner

프로그래머스





1. Python


def solution(n, results):
    board = [[-1 for _ in range(n)] for _ in range(n)]
    for win, lose in results:
        board[win-1][lose-1] = 1
        board[lose-1][win-1] = 0
        
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if board[j][i] == -1:
                    continue
                    
                if board[j][i] == board[i][k]: #j > i, i > k -> j > k
                    board[j][k] = board[j][i]
                    board[k][j] = not board[j][i]
                    
    answer = 0
    for i in range(n):
        if -1 in board[i][:i] + board[i][i+1:]:
            continue
        answer += 1
    return answer



2. C++





3. JavaScript





profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글