프로그래머스(파이썬)/LV.1(파이썬)

    크레인 인형 뽑기 →"열"접근★★ + 전부 1씩 빼주기(람다식)★★

    나의 풀이 def solution(board, moves): stack=[] cnt=0 #j는 열(column)을 의미한다. #len(board)는 행의 갯수를 의미한다. #move리스트에서 1은 0열(column)을 의미한다. 5는 4열(column)을 의미한다. for j in range(len(moves)): for i in range(len(board)): # print(board[i][moves[j]-1]) 열단위로 접근한다. if board[i][moves[j]-1] !=0: #stack processing stack.append(board[i][moves[j]-1]) board[i][moves[j]-1]=0 #스택에 동일한 값인지 아닌지 확인을 한다. if len(stack)>=2 and s..

    폰켓몬★★ → 해설, 조합X

    나의 풀이 def solution(nums): choice_cnt = int(len(nums)//2) kind_cnt = len(set(nums)) if choice_cnt > kind_cnt: return kind_cnt else: return choice_cnt ▶ ex1) nums=[1,2,3,4,5,5,5,5] 라면 전체 포켓몬의 종류의 수(kind_cnt)는 [1,2,3,4,5] =>총 5종류가 된다. ▶ choice_cnt=len(nums)//2=총 마리수//2) ▶ 하지만 최대 가져갈 수 있는 포켓몬은 최대 8마리 중 절반인 4마리(choice_cnt) 이므로 결국엔 4종류 밖에 선택이 안된다. 따라서 4를 return해야 한다. (kindcnt>choicecnt) ▶ ex2) nums=[1..

    키패드 누르기→매개변수로 값주기, 현재값, next값★

    나의 풀이 def solution(numbers, hand): # 1. 왼손 오른손 위치를 초기화 left_key= [1,4,7] right_key= [3,6,9] hand_position=['*', '#'] keyPad = { 1:(0,0), 2:(0,1), 3:(0,2), 4:(1,0), 5:(1,1), 6:(1,2), 7:(2,0), 8:(2,1), 9:(2,2), '*':(3,0), 0:(3,1), '#':(3,2) } # 2. 숫자를 누를 손가락 정하기 answer="" for num in numbers: if num in left_key: hand_position[0]=num answer+="L" elif num in right_key: hand_position[1]=num answer+="R..

    숫자 짝꿍 → 일치 + count() + min(a,b) + len(answer) == a.count('0')★★ + 모든 요소가 0인 경우

    나의 풀이 def solution(X, Y): answer = [] for i in range(10): num=min(X.count(str(i)), Y.count(str(i))) answer.append(num) result =[] for j in range(10): if answer[j] != 0: for _ in range(answer[j]): result.append(str(j)) result.sort(reverse=True) #result에 요소 자체가 없는 경우 if len(result) ==0: return "-1" #result의 모든 요소가 '0'인 경우 elif len(result) == result.count('0'): return '0' return "".join(result) ▶ 모..