정렬 3

[Python | 프로그래머스 | Lv_3] 인사고과

😄 아이디어 1. a, b 의 값 중 하나는 내림차순, 남은 하나는 오름차순으로 정렬한다. 👉 코드에서는 a를 내림차순 b를 오름차순 정렬 2. a의 값이 내림차순으로 정렬되고 있기에 탐색 중 갱신되는 maxB의 값보다 작은 b가 탐색되면 인센티브를 받지 못하는 사원이다. ✔️ 코드 def solution(scores): answer = 1 wanho = scores[0] rs = sorted(scores, key = lambda x: (-x[0], x[1])) maxB = 0 for score in rs: if (score[0] > wanho[0] and score[1] > wanho[1]): return -1 if score[1] >= maxB: maxB = score[1] if wan..

알고리즘 2024.04.21

[Python | 프로그래머스 | Lv_3] 가장 큰 수

😄 아이디어 1. 문자열의 정렬방식 이해 필요 (가장 첫 글자부터 아스키코드로 변환해 비교) 2. number의 조건이 힌트 (1,000 이하) 👉 문자열을 최소 3회 이상 반복시키고 비교 def solution(numbers): nums = list(map(str, numbers)) nums.sort(key = lambda x : x * 4, reverse = True) return str(int(''.join(nums))) 😄 오답 # 오답! from functools import cmp_to_key def solution(numbers): nums = sorted(numbers, key = cmp_to_key(getBigNum)) #print('nums', nums) return str(in..

알고리즘 2024.03.31