[python][프로그래머스_lv1] 숫자 짝꿍 (feat. sort 안 쓰기)
·
코딩테스트/python
나의 첫번째 풀이 아주 제너럴한 접근방식이었을 것 같다..  def number_of_love(X,Y): first = list(X) second = list(Y) common = [] for i in first: if i in second: common.append(i) second.remove(i) if len(common) == 0: return str(-1) elif int(''.join(map(str, common))) == 0: return str(0) else: common.sort(reverse=True) new_number = int(''.join(m..
[python][프로그래머스_lv1] 완주하지 못한 선수 (feat. 해시테이블)
·
코딩테스트/python
왕바보같은 첫 코드 그냥 문제 보고 차집합인 줄 알았음 def solution(participant, completion): str_list = [x for x in participant if x not in completion] answer = str_list return answer 그랬더니 테스트케이스 3번에서 걸리더라 ㅇㅎ 그래 맞아 동명이인이 있을 수 있지 하고 예전 문제들 뒤적거리다 생각난게 파이썬 집합 패키지.. Counter 가 있었다 Counter 는 이렇게 쓰는 애다 from collections import Counter #중복이 있는 리스트를 만듬 fruits = ['apple', 'banana', 'orange', 'apple', 'banana', 'apple'] #카운더에 담음 ..
[python][프로그래머스_lv1] 체육복 (feat. 탐욕법)
·
코딩테스트/python
Description 점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번호의 학생이나 바로 뒷번호의 학생에게만 체육복을 빌려줄 수 있습니다. 예를 들어, 4번 학생은 3번 학생이나 5번 학생에게만 체육복을 빌려줄 수 있습니다. 체육복이 없으면 수업을 들을 수 없기 때문에 체육복을 적절히 빌려 최대한 많은 학생이 체육수업을 들어야 합니다. 전체 학생의 수 n, 체육복을 도난당한 학생들의 번호가 담긴 배열 lost, 여벌의 체육복을 가져온 학생들의 번호가 담긴 배열 reserve가 매개변수로 주어질 때, 체육수업을 들을 수 있는 학생의 최댓값을 return 하도록 soluti..
[python][프로그래머스_lv1] 로또의 최고 순위와 최저 순위
·
코딩테스트/python
Description Lotto 6/45(Hereinafter 'Lotto') is a popular lottery game where six numbers are drawn from a pool of 45 numbers. The lottery prize tiers are as follows1: Prize TiersRequirement 1 All six numbers match 2 Five numbers match 3 Four numbers match 4 Three numbers match 5 Two numbers match 6 (no prize) All other cases You bought a lotto ticket and have been waiting for the draw. However, y..
허니비 honeybee
'코딩테스트/python' 카테고리의 글 목록