반응형 Coding Test/Python53 [프로그래머스] 과제 진행하기 Python 풀이 문제 구현 이 문제는 따로 쉽게 푸는 방법이 없는 것 같아 문제를 그대로 따라가면서 구현을 하면 된다. 우선 기본적으로 plans를 시간순서로 sorting 한 후 시작하는 게 좋다. 코드 def solution(plans): plans = sorted(plans, key=lambda x : x[1]) todostack = [] answer = [] nowtime = 0 beforetime = -1 for i in range(len(plans)): h,m = plans[i][1].split(':') plans[i][1] = int(h)*60+int(m) if i>0: remainingTime = plans[i][1] - plans[i-1][1] if remainingTime - int(plans[i-1].. 2023. 4. 6. [프로그래머스] 연속 펄스 부분 수열의 합 Python 풀이 문제 구현 sequence에 [-1, 1, -1, 1......] 을 곱한 pulse배열과 sequence에 [1, -1, 1, -1......] 을 곱한 revpulse배열을 준비한다. 여기서 편의를 위해 accumulate 함수를 사용할 건데 배열을 돌며 이전 값에 따른 처리(기본 덧셈)를 해주는 함수이다. 코드 부분에서 추가로 설명하겠다. 그렇게 되면 각 배열 인덱스에 더해진 값이 있을건데 그중의 max값을 리턴하면 된다. 코드 from itertools import accumulate def solution(sequence): pulse = [((-1)**(i%2))*sequence[i] for i in range(len(sequence))] revpulse = [i*-1 for i in puls.. 2023. 3. 24. [Codility] Carol of the Code Python (코드 업데이트) 파이썬으로 코딜리티 챌린지를 도전해봤다. 해당 챌린지가 종료되면 풀이를 올려보겠다. 챌린지가 종료되어 코드를 올려보겠다. 문제는 아래에 있다. https://app.codility.com/cert/view/cert7CAQA7-RVJBNWEEK67SVFHW/ Codility app.codility.com 풀이 코드는 아래와 같이 구현할 수 있다. # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def rotate(s, num): return s[num:]+s[:num] def ispretty(s1, s2): return True if s1[1] == s2[3] else False def solu.. 2023. 3. 13. [프로그래머스] 혼자서 하는 틱택토 Python 풀이 문제 틱택토는 3x3에서 하는 3목이라고 보면 된다. 구현 O와 X의 가로와 세로, 대각선 라인의 완성된 3목의 수를 각각 세어서 가능한 상황인지 판단해야 한다. 코드 def solution(board): strboard = ''.join(board) valid = strboard.count('O')-strboard.count('X') if valid not in [0,1]: return 0 colboard = list(zip(*board)) ocnt=0 xcnt=0 for i in range(3): if colboard[i].count('O')==3 or board[i].count('O')==3: ocnt+=1 if colboard[i].count('X')==3 or board[i].count('X').. 2023. 3. 9. 이전 1 2 3 4 5 6 7 ··· 14 다음 반응형