[프로그래머스 Lv1] 추억 점수(python, 해시)
·
CodingTest/Programmers
[문제][풀이]def solution(name, yearning, photo): answer = [] for i in range(len(photo)): missing_score = 0 for j in photo[i]: if j in name: missing_score += yearning[name.index(j)] answer.append(missing_score) return answer나는 인덱싱으로 풀었지만 시간복잡도가 O(P⋅N^2) 이므로 시간초과날 확률 높음! 아래는 해시로 다시 풀어본 것, 아래코드는 시간복잡도 O(N + P⋅M)def solution(name, yearning, photo):..
[프로그래머스 Lv1] 카드 뭉치(python, 구현)
·
CodingTest/Programmers
[문제][풀이]def solution(cards1, cards2, goal): a, b = 0, 0 for i in goal: if a [링크]https://school.programmers.co.kr/learn/courses/30/lessons/159994 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr
[프로그래머스 Lv1] 비밀지도(python, 구현)
·
CodingTest/Programmers
[문제][풀이]def solution(n, arr1, arr2): answer = [] for i in range(n): mapped = bin(arr1[i]|arr2[i])[2:].zfill(n) matched = mapped.replace("1", "#").replace("0", " ") answer.append(matched) return answerzfill(n): 앞에 0을 붙여서 문자열 길이를 n으로 맞춰주는 메서드[링크]https://school.programmers.co.kr/learn/courses/30/lessons/17681 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠..
[프로그래머스 Lv1] 폰켓몬(python, 해시)
·
CodingTest/Programmers
[문제][풀이]def solution(nums): answer = 0 not_duplication = [] my_pocketmon = len(nums) // 2 for i in nums: if i not in not_duplication: not_duplication.append(i) return min(my_pocketmon, len(not_duplication))[링크]https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr
[프로그래머스 Lv1] 기사단원의 무기(python, 구현)
·
CodingTest/Programmers
[문제][풀이]def solution(number, limit, power): attack = [] answer = 0 for i in range(1, number + 1): num = 0 for j in range(1, int(i**0.5) + 1): if i % j == 0: if j == i//j: num += 1 else: num += 2 attack.append(num) for i in attack: if i > limit: answer += power ..
[프로그래머스 Lv1] 모의고사(python, 완전탐색)
·
CodingTest/Programmers
[문제][풀이]def solution(answers): pattern = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]] scores = [0, 0, 0] for i, ans in enumerate(answers): for j, pat in enumerate(pattern): if ans == pat[i % len(pat)]: scores[j] += 1 max_score = max(scores) return [idx + 1 for idx, score in enumerate(scores) if score == max_score][링크]..
[프로그래머스 Lv1] 2016년(python, 구현)
·
CodingTest/Programmers
[문제][풀이]def solution(a, b): month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] day = ['FRI', 'SAT', 'SUN', 'MON', 'TUE', 'WED', 'THU'] total = 0 for i in range(a - 1): total += month[i] total += b - 1 return day[total % 7] [문제 링크]http://school.programmers.co.kr/learn/courses/30/lessons/12901 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.c..
[프로그래머스 Lv2] 피보나치 수(python, DP)
·
CodingTest/Programmers
문제링크: https://school.programmers.co.kr/learn/courses/30/lessons/12945 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krdef solution(n): answer = 0 sequence = [1, 1] for i in range(n - 2): sequence.append(sequence[i] + sequence[i + 1]) return sequence[-1] % 1234567