본문 바로가기

반응형

코딩 테스트

(98)
DP - 11726. 2×n 타일링 문제 www.acmicpc.net/problem/11726 11726번: 2×n 타일링 2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다. www.acmicpc.net 잠깐만 참고로, 결과 값은 10007로 나눈 값입니다 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new Buffer..
DP - 1003. 피보나치 함수 문제 www.acmicpc.net/problem/1003 1003번: 피보나치 함수 각 테스트 케이스마다 0이 출력되는 횟수와 1이 출력되는 횟수를 공백으로 구분해서 출력한다. www.acmicpc.net 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { int[] results0 = new int[41]; int[] results1 = new int[41]; results0[0] = 1; results1[0] = 0; results0[..
DP - 9095. 1, 2, 3 더하기 문제 www.acmicpc.net/problem/9095 9095번: 1, 2, 3 더하기 각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다. www.acmicpc.net 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { int[] results = new int[12]; results[1] = 1; results[2] = 2; results[3] = 4; for (int i = 4; i < 11; i++..
DP - 1463. 1로 만들기 문제 www.acmicpc.net/problem/1463 1463번: 1로 만들기 첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다. www.acmicpc.net 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenize..
DP - 2839. 설탕 배달 문제 www.acmicpc.net/problem/2839 2839번: 설탕 배달 상근이는 요즘 설탕공장에서 설탕을 배달하고 있다. 상근이는 지금 사탕가게에 설탕을 정확하게 N킬로그램을 배달해야 한다. 설탕공장에서 만드는 설탕은 봉지에 담겨져 있다. 봉지는 3킬로그 www.acmicpc.net 코드 import Foundation while let input = readLine(){ var result = -1 var num = Int(input)! for five in stride(from: num/5, through: 0, by: -1) { var tempKg = num - (5*five) if tempKg % 3 == 0 { result = five + (tempKg/3) break } } print..
[LeetCode] 11. Container With Most Water 문제 leetcode.com/problems/container-with-most-water/ Container With Most Water - 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 { func maxArea(_ height: [Int]) -> Int { var left = 0 var right = height.count-1 var maxVolume = 0 while left < right { let tempVolume =..
[LeetCode] 15. 3Sum 문제 leetcode.com/problems/3sum/ 3Sum - 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 { func threeSum(_ nums: [Int]) -> [[Int]] { var arraySet = Set() var sortedNums = nums.sorted() var maxIndex = sortedNums.count-1 for y in 0.. 0, sortedNums[y] == sortedNums[y-1]..
[LeetCode] 33. Search in Rotated Sorted Array 문제 leetcode.com/problems/search-in-rotated-sorted-array/ Search in Rotated Sorted Array - 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 잠깐만 단순 포문으로 풀수 있겠지만, 문제 하단에 이런 문장이 있네요. Follow up: Can you achieve this in O(log n) time complexity? 코드 class Solution { func search(_ nums: [In..
[LeetCode] 153. Find Minimum in Rotated Sorted Array 문제 leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated Sorted Array - 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 코드 (22년 2월 15일 구현) class Solution { func findMin(_ nums: [Int]) -> Int { var leftIndex = 0 var rightIndex = nums.count - 1 if nums[l..
[LeetCode] 152. Maximum Product Subarray 문제 leetcode.com/problems/maximum-product-subarray/ Maximum Product Subarray - 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 { func maxProduct(_ nums: [Int]) -> Int { var minValue = nums[0] var maxValue = nums[0] var result = nums[0] for i in 1..

반응형