728x90
반응형
SMALL
def solution(n):
    answer = []
    for i in range(2,n+1):
        pre = 0
        while pre != n:
            pre = n
            if n%i==0:
                if not i in answer:
                    answer.append(i)
                n = n//i
        if n==1:
            break
    
    return answer
728x90
반응형
LIST

'IT > 코딩테스트' 카테고리의 다른 글

프로그래머스 모의고사 문제 답 코딩  (1) 2024.05.14
프로그래머스 폰켓몬 설명 풀이 코드 답 코딩  (0) 2024.05.14
특이한정렬  (0) 2024.05.08
안전지대  (0) 2024.05.04
정수를 나선형으로 배치하기  (0) 2024.05.04
728x90
반응형
SMALL
def solution(board):
    answer = []
    
    for i in board:
        answer.append(list(i))
        
    
    for i, r in enumerate(board):
        for j, v in enumerate(r):
            if v==1:
                for q in range(i-1,i+2):
                    for r in range(j-1,j+2):                        
                        if 0<=q and q <len(board) and 0<=r and r < len(board[0]):
                            answer[q][r] = 1
    
    answer = len(board) * len(board[0]) - sum(list(map(sum,answer)))
    
    return answer
728x90
반응형
LIST
728x90
반응형
SMALL
def solution(n):
    
    answer = [[0]*n for i in range(n)]
    
    
    x, y = 0, 0
    move_state = 0#right==0, down = 1, left=2, up=3 
    
    for i in range(1,(n*n)+1):
        answer[y][x] = i
        
        if move_state == 0: x+=1
        elif move_state == 1: y+=1
        elif move_state == 2: x-=1
        elif move_state == 3: y-=1
        
        if (move_state==0 and (x+1 >= n or  answer[y][x+1]!=0)) or (move_state==1 and (y+1 >= n or  answer[y+1][x]!=0)) or (move_state==2 and (x-1 < 0 or  answer[y][x-1]!=0)) or (move_state==3 and (y-1 < 0 or  answer[y-1][x]!=0)):
            move_state =(move_state+1)%4
            
            
        
    return answer
728x90
반응형
LIST

'IT > 코딩테스트' 카테고리의 다른 글

프로그래머스 모의고사 문제 답 코딩  (1) 2024.05.14
프로그래머스 폰켓몬 설명 풀이 코드 답 코딩  (0) 2024.05.14
특이한정렬  (0) 2024.05.08
소인수분해  (0) 2024.05.07
안전지대  (0) 2024.05.04

+ Recent posts