본문 바로가기

PS/프로그래머스27

프로그래머스 전화번호 목록도움말 python 1. 문제 2. 풀이 sort 하면 길이대로 정렬되는 것 str.startswith(str2) 시작하는 것 확인하는 라이브러리 3. 구현 def solution(phone_book): answer = True phone_book.sort() for num1, num2 in zip(phone_book, phone_book[1:]): if num2.startswith(num1): return False return True 2021. 6. 14.
프로그래머스 짝지어 제거하기 python 1. 문제 2. 풀이 앞뒤를 비교하므로 stack 자료구조 이용! 2. 구현 정답코드 def solution(s): answer = -1 stk = [] for c in s: if stk: if stk[-1]==c: stk.pop() else: stk.append(c) else: stk.append(c) if stk: answer=0 else: answer=1 return answer 답은 나오는 것 같은데 시간초과. 사실 그럴법도 하다. def solution(s): answer = -1 li = [ 'aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'gg', 'kk', 'll', 'mm', 'nn', 'oo', 'pp', 'qq', 'rr', 'ss', .. 2021. 6. 14.
프로그래머스 오픈채팅방 python 1. 문제 2. 풀이 dictionary 형태 사용하기 3. 구현 def solution(record): answer = [] dic={} for item in record: item = item.split(' ') # item.split(' ') 하면 달라지는 것이 없다. if item[0] != 'Leave': dic[item[1]] = item[2] for item in record: item = item.split(' ') if item[0]=='Enter': answer.append(f"{dic[item[1]]}님이 들어왔습니다.") if item[0]=='Leave': answer.append(f"{dic[item[1]]}님이 나갔습니다.") return answer 2021. 6. 14.
프로그래머스 124나라의 숫자 python 1.문제 2.풀이 q,r = divmod(N, Q) 단점은 조금 느리다는 것. 3.구현 def solution(n): answer = '' if n 2021. 6. 14.
반응형