본문 바로가기

코딩테스트9

13. Roman to Integer 13. Roman to Integer Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from l.. 2023. 1. 29.
1. Two Sum (Leet Code) Python 풀이 1. Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1 Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return .. 2023. 1. 24.
백준(Baekjoon) 1463번 : 1로 만들기 with Python 백준에서 문제 보기 : https://www.acmicpc.net/problem/1463 1463번: 1로 만들기 첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다. www.acmicpc.net 난이도 실버 3 알고리즘 1) 0으로 리스트 초기화 2) 점화식 이용 f(x - 1) + 1 f(x / 2) + 1 f(x / 3) + 1 최소값 구하기 해결 방안 문제에서 요구하는 사항은 'DP(Dynamic programming)'를 구현하여 해결하는 개념을 요구합니다. import sys input = sys.stdin.readline N = int(input()) dp = [0 for _ in range(N+1)] for i in range(1, N+1): if i == 1: dp.. 2021. 1. 22.
백준(Baekjoon) 1874번 : 스택 수열 with Python 백준에서 문제 보기 : https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net 난이도 실버 3 알고리즘 1) N번 반복 입력 2) count로 값 세면서 stack에 저장 , 동시에 result 스택에도 '+' 저장 3) stack[-1] 번째 값이 입력값과 같을때 stack pop , result '-' 아닐시 NO 해결 방안 문제에서 요구하는 사항은 '스택'을 구현하.. 2021. 1. 22.