Algorithm
-
[🤷♀️ 백준] 11726번. 2xn 타일링 (PYTHON)Algorithm/1일 1코테 2020. 11. 13. 13:10
📌 문제 www.acmicpc.net/problem/11726 11726번: 2×n 타일링 2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다. www.acmicpc.net 📌 답 # 런타임 에러 N = int(input()) a = [0 for _ in range(N+1)] a[0] = 0 a[1] = 1 a[2] = 2 for i in range(3, len(a)): a[i] = a[i-1] + a[i-2] print(a[N]%10007) # 수정 N = int(input()) a = [0,1,2] for i in range(3, 1001): a.append(a[i-1] + a[i-2]) ..
-
[🤷♀️ 백준] 1463번. 1로 만들기 (PYTHON)Algorithm/1일 1코테 2020. 11. 13. 12:24
📌 문제 및 문제설명 www.acmicpc.net/problem/1463 1463번: 1로 만들기 첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다. www.acmicpc.net 📌 답 n = int(input()) #1 a = [0 for _ in range(n+1)] #2 for i in range(2, len(a)): #3 a[i] = a[i-1] + 1 if i%3 == 0: a[i] = min(a[i], a[i//3]+1) if i%2 == 0: a[i] = min(a[i], a[i//2]+1) print(a[n]) 다이나믹 프로그래밍으로 푸는 문제! 1. input을 통해 입력값을 받는다. 2. n+1만큼 크기의 리스트를 만들어준다! 이 리스트엔 인덱스 숫자가 1이 되..
-
[🤷♀️ Leetcode] 509. Fibonascci NumberAlgorithm/1일 1코테 2020. 11. 9. 14:39
문제설명 피보나치 수를 구하라 leetcode.com/problems/fibonacci-number/submissions/ Fibonacci Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 class Solution: dp = collections.defaultdict(int) def fib(self, N: int) -> int: if N
-
[💕 Leetcode] 169. Majority ElementAlgorithm/1일 1코테 2020. 11. 9. 13:42
📌 문제설명 과반수를 차지하는 엘리먼트를 출력하라 leetcode.com/problems/majority-element/submissions/ Majority Element - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 📌 내 풀이 # 모든 리스트엔 과반수 이상인 수가 있다는 가정이 존재한다. from collections import Counter class Solution: def majorityElement(self, nums: List[int]) ->..
-
[💕 프로그래머스 Python] 영어 끝말잇기Algorithm/1일 1코테 2020. 11. 1. 17:32
📌 문제 programmers.co.kr/learn/courses/30/lessons/12981 코딩테스트 연습 - 영어 끝말잇기 3 [tank, kick, know, wheel, land, dream, mother, robot, tank] [3,3] 5 [hello, observe, effect, take, either, recognize, encourage, ensure, establish, hang, gather, refer, reference, estimate, executive] [0,0] programmers.co.kr 📌 내 풀이 def solution(n, words): aleady = [] # 이미 말했던 단어 player = 0 # 플레이어 번호 count = 1 # 게임 라운드 las..
-
[💕 프로그래머스 Python] 올바른 괄호Algorithm/1일 1코테 2020. 10. 30. 16:25
프로그래머스 올바른 괄호 💕 문제설명 programmers.co.kr/learn/courses/30/lessons/12909 코딩테스트 연습 - 올바른 괄호 괄호가 바르게 짝지어졌다는 것은 '(' 문자로 열렸으면 반드시 짝지어서 ')' 문자로 닫혀야 한다는 뜻입니다. 예를 들어 ()() 또는 (())() 는 올바른 괄호입니다. )()( 또는 (()( 는 올바르지 않은 괄호 programmers.co.kr 💕 내가 쓴 답 def solution(s): answer = True left = 0 # ( 괄호 right = 0 # ) 괄호 if s[0] == ')' or s[-1] == '(': # 맨 처음이 ) 거나 마지막이 ( 면 성립 X return False else: for i in s: if i ==..
-
[💕 프로그래머스 Python] 다음 큰 숫자Algorithm/1일 1코테 2020. 10. 28. 21:21
⛄ 프로그래머스 연습문제 2단계 다음 큰 숫자 programmers.co.kr/learn/courses/30/lessons/12911 코딩테스트 연습 - 다음 큰 숫자 자연수 n이 주어졌을 때, n의 다음 큰 숫자는 다음과 같이 정의 합니다. 조건 1. n의 다음 큰 숫자는 n보다 큰 자연수 입니다. 조건 2. n의 다음 큰 숫자와 n은 2진수로 변환했을 때 1의 갯수가 같습니 programmers.co.kr def solution(s): n = 1000000 b = bin(s).count('1') for i in range(s+1, n): if b == bin(i).count('1'): return i def nextBigNumber(n): c = bin(n).count('1') for m in ran..
-
[💕 프로그래머스 Python] 더 맵게Algorithm/1일 1코테 2020. 10. 28. 20:56
프로그래머스 연습문제 2단계 더 맵게 🔥 문제 programmers.co.kr/learn/courses/30/lessons/42626 코딩테스트 연습 - 더 맵게 매운 것을 좋아하는 Leo는 모든 음식의 스코빌 지수를 K 이상으로 만들고 싶습니다. 모든 음식의 스코빌 지수를 K 이상으로 만들기 위해 Leo는 스코빌 지수가 가장 낮은 두 개의 음식을 아래와 같 programmers.co.kr 내 풀이 # 1차 시도 - 81점 import heapq def solution(s, k): heapq.heapify(s) answer = 0 while s: if s[0] >= k: return answer a1=heapq.heappop(s) a2=heapq.heappop(s) heapq.heappush(s, a1+..