본문 바로가기
반응형

프로그래머스/2단계108

(Python/LV2) 삼각 달팽이 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/68645 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(n): tri = [[0 for i in range(1, n+1)] for i in range(1, n+1)] num = 1 x,y =-1, 0 for i in range(n): for j in range(i, n): if i % 3 == 0: # 아래 x += 1 elif i % 3 == 1: # 오른쪽 y += 1 elif i % 3 == 2: # 위쪽.. 2022. 10. 5.
(Python/LV2) 큰 수 만들기 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/42883 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(number, k): stack = [] for n in number: while stack and stack[-1] 0: stack.pop() k -= 1 stack.append(n) # 제거 횟수를 다 사용 안했을때 if k > 0: stack = stack[:-k] return ''.join(stack) 넣은 다음 뒤에 오는 수.. 2022. 10. 5.
(Python/LV2) 124 나라의 숫자 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/12899 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 from itertools import product def solution(n): words = ["1","2","4"] list = [] count = n if n == 1 : return "1" while True: for i in range(1,n): for j in product(words, repeat = i): list.append("".join(j)) if len(l.. 2022. 10. 5.
(Python/LV2) 가장 큰 수 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: 아래 풀이는 시간초과로 다 틀리는 풀이 from itertools import permutations, product def solution(numbers): res = list(permutations(numbers, len(numbers))) num_str = [] for i in range(len(res)): num_str.append("".join(map(str,res[i].. 2022. 10. 5.
(Python/LV2) 2*n 타일링 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/12900 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(n): dp = [0 for i in range(n+1)] dp[1], dp[2] = 1, 2 for i in range(3,n+1): dp[i] = (dp[i-1] + dp[i-2]) % 1000000007 return dp[n] 피보나치수열 혹인 Dp 사용 2022. 10. 4.
(Python/LV2) 2개 이하로 다른 비트 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/77885 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(numbers): res = [] for number in numbers: number = int(number) if number % 2 == 0: res.append(number+1) else: now = '0' + bin(number)[2:] index = now.rfind("0") now_list = list(now) now_list[index] = .. 2022. 10. 4.
반응형