전체 (290) 썸네일형 리스트형 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.. [LeetCode] 53. Maximum Subarray 문제 leetcode.com/problems/maximum-subarray/ Maximum 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 잠깐 우리가 같이 풀었던 로직을 활용해야 하는 로직입니다. 저는 2가지 방식으로 풀었습니다. 코드 (22년 2월 15일 풀이) class Solution { func maxSubArray(_ nums: [Int]) -> Int { var maxSum = nums[0] var sumValue = nums[0].. [LeetCode] 238. Product of Array Except Self 문제 leetcode.com/problems/product-of-array-except-self/ Product of Array Except Self - 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 잠깐 array에서 자기 자신을 제외한 곱의 값을 넘겨 주는 문제. 코드 class Solution { func productExceptSelf(_ nums: [Int]) -> [Int] { var answer: [Int] = Array(repeating: 0, c.. 이전 1 ··· 9 10 11 12 13 14 15 ··· 29 다음