코딩 테스트(JAVA) 81

[programmers] 삼각 달팽이

https://school.programmers.co.kr/learn/courses/30/lessons/68645 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 정수 n이 매개변수로 주어집니다. 다음 그림과 같이 밑변의 길이와 높이가 n인 삼각형에서 맨 위 꼭짓점부터 반시계 방향으로 달팽이 채우기를 진행한 후, 첫 행부터 마지막 행까지 모두 순서대로 합친 새로운 배열을 return 하도록 solution 함수를 완성해 주세요. 제한사항 n은 1 이상 1,000 이하입니다. 입출력 예 n result 4 [1,2,9,3,10,8,4,5,6,7] 5 [1,2..

[문제12][LeetCode] 121. 주식을 사고팔기 가장 좋은 시점

https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/ You are given an array prices where prices[i] is the price of a given stock on the ith day. 주어진 배열 prices에서 prices[i]는 i번째 날의 특정 주식 가격입니다. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. 하나의 주식을 사는 날과 미래의 다른 날에 그 주식을 판매하는 것으로 이익을 극대화..

[문제11][LeetCode] 238. 자신을 제외한 배열의 곱

https://leetcode.com/problems/product-of-array-except-self/description/ Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. 정수 배열 nums가 주어졌을 때, answer[i]가 nums[i]를 제외한 nums의 모든 요소의 곱과 같게 하는 배열 answer를 반환해주세요. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. nums의 어떤 접두사나 접..

[문제10][LeetCode] 561. 배열 파티션 I

https://leetcode.com/problems/array-partition/ Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. 2n개의 정수로 구성된 정수 배열 nums가 주어졌을 때, 이 정수들을 n 쌍의 (a1, b1), (a2, b2), ..., (an, bn)과 같이 그룹화하여 모든 i에 대해 min(ai, bi)의 합이 최대화되도록 합니다. 최대화된 합을 반환하세요. Example 1: Inpu..

[백준 2751번, 백준 10814번, LeetCode 179번] 정렬 문제 풀이

[백준 2751번] 수 정렬하기 2 https://www.acmicpc.net/problem/2751 2751번: 수 정렬하기 2 첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다. www.acmicpc.net 접근 방법 N개의 수가 주어졌을 때, 오름차순 정렬하는 문제입니다. 1. 문자열로 입력받은 부분을 Integer.parseInt() 메서드를 통해 정수로 바꿔줍니다. 2. 배열을 만든 후 for문을 돌면서 입력받은 문자열 ➡ 정수를 차례로 넣습니다. 3. 정렬 후 출력합니다. 코드 구현 1. 실패 코드 import java.util.*; import ..