코딩 테스트/Level 1
-
프로그래머스 / 명예의 전당 (1)코딩 테스트/Level 1 2022. 11. 24. 22:13
https://school.programmers.co.kr/learn/courses/30/lessons/138477 파이썬 힙큐를 이용하면 조금 빠르려나... def solution(k, score): import heapq answer, honer = [], [] for each in score: heapq.heappush(honer, each) if len(honer) > k: heapq.heappop(honer) answer.append(honer[0]) # honer[0] = 가장 작은 원소 return answer 테스트 1 〉통과 (0.01ms, 10MB) 테스트 2 〉통과 (0.01ms, 10.1MB) 테스트 3 〉통과 (0.01ms, 10.1MB) 테스트 4 〉통과 (0.01ms, 9.97..
-
프로그래머스 / 기사단원의 무기코딩 테스트/Level 1 2022. 11. 17. 19:14
https://school.programmers.co.kr/learn/courses/30/lessons/136798 파이썬 약수는 제곱근(루트)를 이용해서 계산을 줄일 수 있다. def solution(number, limit, power): answer = 0 for i in range(1, number + 1): sqrt_i = i ** .5 count = sum(1 for j in range(1, int(sqrt_i) + 1) if i % j == 0) * 2 - (0 if sqrt_i % 1 else 1) answer += power if limit < count else count return answer 코틀린 class Solution { fun solution(number: Int, lim..
-
프로그래머스 / 과일 장수코딩 테스트/Level 1 2022. 11. 10. 22:19
https://school.programmers.co.kr/learn/courses/30/lessons/135808 파이썬 for 문을 이용. def solution(k, m, score): score.sort(reverse=True) return sum(score[index] * m for index in range(m - 1, len(score), m)) slice를 이용. def solution(k, m, score): return sum(sorted(score, reverse=True)[m - 1:: m]) * m 코틀린 class Solution { fun solution(k: Int, m: Int, score: IntArray): Int { val sortedScore = score.sorte..
-
프로그래머스 / 햄버거 만들기코딩 테스트/Level 1 2022. 10. 27. 23:25
https://school.programmers.co.kr/learn/courses/30/lessons/133502 파이썬 def solution(ingredient): stack = [] answer = 0 for each in ingredient: stack.append(each) if stack[-4:] == [1, 2, 3, 1]: answer += 1 del stack[-4:] return answer 코틀린 class Solution { fun solution(ingredient: IntArray): Int { var answer = 0 val bugger = listOf(1, 2, 3, 1) val stack = mutableListOf() for (each in ingredient) { s..
-
프로그래머스 / 옹알이 (2)코딩 테스트/Level 1 2022. 10. 27. 23:16
https://school.programmers.co.kr/learn/courses/30/lessons/133499 파이썬 def solution(babbling): answer = 0 for each in babbling: for index, text in enumerate(("aya", "ye", "woo", "ma")): each = each.replace(text, str(index)) if each.isdigit(): if '00' not in each: if '11' not in each: if '22' not in each: if '33' not in each: answer += 1 return answer 코틀린 class Solution { fun solution(babbling: Arr..
-
프로그래머스 / 콜라 문제코딩 테스트/Level 1 2022. 10. 27. 23:15
https://school.programmers.co.kr/learn/courses/30/lessons/132267 파이썬 def solution(a, b, n): answer = 0 while n >= a: quotient = n // a # 몫 new_bottle = quotient * b # 새 콜라 n -= a * quotient # 마트에 가져다 준 빈 병 answer += new_bottle n += new_bottle return answer import sys sys.setrecursionlimit(10000) def solution(a, b, n): if n < a: return 0 quotient = n // a new_bottle = quotient * b return new_bott..
-
프로그래머스 / 삼총사코딩 테스트/Level 1 2022. 10. 27. 23:14
https://school.programmers.co.kr/learn/courses/30/lessons/131705 파이썬 억지스럽게... from itertools import combinations solution = lambda number: sum(1 for each in combinations(number, 3) if sum(each) == 0) 정상적으로... from itertools import combinations def solution(number): return sum(1 for each in combinations(number, 3) if sum(each) == 0) 코틀린 class Solution { fun solution(number: IntArray): Int { var a..
-
프로그래머스 / 숫자 짝꿍코딩 테스트/Level 1 2022. 10. 27. 23:13
https://school.programmers.co.kr/learn/courses/30/lessons/131128 파이썬 억지스럽게... from collections import Counter solution = lambda num1, num2: ('0' if (result := ''.join(each * inter_n[each] for each in sorted(inter_n, reverse=True)))[0] == '0' else result) if (inter_n := Counter(list(num1)) & Counter(list(num2))) else "-1" 덜 억지스럽게... from collections import Counter def solution(num1, num2): return..