프로그래머스 월코챌 시즌 3

골솔·2021년 9월 10일
0

알고문제풀기

목록 보기
24/27

1번

def solution(numbers):
    return 45-sum(numbers)

2번

def solution(grid):
    answer = []
    cycle = 0
    m = len(grid)
    o = len(grid[0])
    edges = [[[False for _ in range(4)] for _ in range(o)]for _ in range(m)]
    dx = [0,0,1,-1]
    dy = [1,-1,0,0]
    for i in range(m):
        for j in range(o): 
            for k in range(4): # 시작지점
                x, y, kk = i, j, k
                while True:
                    if edges[x][y][kk] == False:
                        edges[x][y][kk] = True
                        x, y = (x+dx[kk])%m, (y+dy[kk])%o
                        if grid[x][y]=='L':
                            if kk==0: kk = 3
                            elif kk==1: kk = 2
                            elif kk==2: kk = 0
                            else: kk = 1
                        elif grid[x][y]=='R':
                            if kk==0: kk = 2
                            elif kk==1: kk = 3
                            elif kk==2: kk = 1
                            else: kk = 0
                        cycle += 1
                    else: 
                        if cycle != 0:
                            answer.append(cycle)
                            cycle = 0
                        break
    answer.sort()
    return answer
profile
골때리는이솔

0개의 댓글