본문 바로가기

분류 전체보기431

www.acmicpc.net/problem/1568 1568번: 새 N마리의 새가 나무에 앉아있고, 자연수를 배우기 원한다. 새들은 1부터 모든 자연수를 오름차순으로 노래한다. 어떤 숫자 K를 노래할 때, K마리의 새가 나무에서 하늘을 향해 날아간다. 만약, 현 www.acmicpc.net 예를 들어 10이 목표값이면 1 + 2 + 3 + 4 = 10 의 count 4 14가 목표값이면 1 + 2 + 3 + 4 = 10인상태에서 + 5면 15가 되기 때문에 1로 초기화해서 카운트를 센다 10 + (1+2+3) + 1 = 14 . 카운트는 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import java.util.*; class Main { publi.. 2020. 11. 21.
Best Time to Buy and Sell Stock leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 1 2 3 4 5 6 7 8 9 10 11 12 13 import java.util.*; class Solution { public int maxProfit(int[] prices) { int maxProfit = 0, minProfit = Integer.MA.. 2020. 11. 20.
Contains Duplicate leetcode.com/problems/contains-duplicate/ Contains Duplicate - 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.*; class Solution { public boolean containsDuplicate(int[] nums) { Map map = new HashMap(); boolean isExisted = .. 2020. 11. 20.
Two Sum II leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input array is sorted - 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 배열과 배열내 두 수의 값을 만들어야하는 타겟값을 입력받는다. 1. 배열을 순회한다. 2. Map에 ( 타겟값 - 배열의 내부의 값 ), 배열 인덱스로 값을 넣는다. 예를 들어 { 1,2,3,4} 인데 target 값이 3이라면 맨처음에는 3-1 이 키.. 2020. 11. 19.