본문 바로가기
728x90

코딩테스트4

[code signal / 코드시그널] are Equally Strong ✨ Description Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. Given your and your friend's arms' lifting capabilities find out if you two are equally strong. ✨ 문제 들어올릴 수 있는 가장 무거운 무게가 같으면 두 팔을 똑.. 2022. 5. 30.
[code signal / 코드시그널] Sort by height ✨ Description Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees. People can be very tall! ✨ 문제 몇몇 사람들이 공원에서 일렬로 서 있다. 그들 사이에는 움직일 수 없는 나무들이 있다. 당신의 임무는 나무를 움직이지 않고 사람들을 그들의 키에 따라 오름차순으로 정렬시키는 것이다. 사람들의 키가 매우 클 수 있다. 👉 배열에 -1로 주어진 나무의 위치는 변경시키지 않고.. 2022. 5. 30.
[프로그래머스] 124나라의 숫자 - 파이썬 문제 코딩테스트 연습 - 124 나라의 숫자 | 프로그래머스 (programmers.co.kr) level 2에 있는 문제이다. 내 코드 def solution(n): x=n-1 answer='' while True: x,y=divmod(x,3) if y==0: answer+='1' elif y==1: answer+='2' else: answer+='4' if x==0: break x=x-1 return answer[::-1] 반복해서 3으로 나누면서 나머지를 0,1,2 각 경우에 따라 answer에 1,2,4를 추가한다. 몫이 0이되면 반복을 멈춘다. 마지막으로 문자열 answer를 reverse해주는 코드이다! 이때까지 코테를 많이 안풀어봐서 일단 하나하나 직접 적어보며 문제 이해부터 했다. 자연수를.. 2022. 2. 12.
[프로그래머스] 두개 뽑아서 더하기 - 파이썬 문제 내 풀이 def solution(numbers): l=len(numbers) answer = [] index=0 for i in range(l-1): for j in range(i+1, l): answer.append(numbers[i] + numbers[j]) answer=list(set(answer)) answer.sort() return answer for 문 안에 for문으로 덧셈을 해주고 answer 리스트에 append로 값을 추가해주었다 -> 리스트안에 값을 추가할때 insert 나 append로 추가 ​ set() -> 중복제거 sort() -> 정렬 근데 set()이랑 sort() 순서를 바꿔서 했을때는 오류가 났었다 😅 다른 풀이 sort()와 sorted()의 차이점? - sor.. 2022. 2. 12.
728x90