본문 바로가기

전체 글

(185)
LeetCode: 47번 (Permutations II) [JAVA] 문제 링크 https://leetcode.com/problems/permutations-ii/ Permutations II - LeetCode Permutations II - Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. Example 1: Input: nums = [1,1,2] Output: [[1,1,2], [1,2,1], [2,1,1]] Example 2: Input: nums = [1,2,3] Output: [[ leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 순열 순서 저장용 arr 생성 (모든 원소 -1로 초..
백준: 15486번 (퇴사 2) [JAVA] 문제 링크 https://www.acmicpc.net/problem/15486 15486번: 퇴사 2 첫째 줄에 N (1 ≤ N ≤ 1,500,000)이 주어진다. 둘째 줄부터 N개의 줄에 Ti와 Pi가 공백으로 구분되어서 주어지며, 1일부터 N일까지 순서대로 주어진다. (1 ≤ Ti ≤ 50, 1 ≤ Pi ≤ 1,000) www.acmicpc.net 풀이 전체적인 풀이 과정은 다음과 같다. 각 날짜 속 상담 소요일과 금액을 저장할 배열과 dp용 배열을 생성 전체 요일 N을 받아 배열 초기화, 그리고 전체 N번에 걸쳐 각 날짜 상담의 소요일과 금액을 받아 저장 첫째날부터 N번째 날까지 계산 반복 1) 현재 요일의 상담 누적값과 이전 날의 상담 누적값 중 더 큰 값을 비교해 현재값에 저장 2) 이전 날의 ..
LeetCode: 46번 (Permutations) [JAVA] 문제 링크 https://leetcode.com/problems/permutations/ Permutations - LeetCode Permutations - Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0 leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 순열 순서 저장용 arr 생성 (모든 원소 -1로 초기화) 순..
LeetCode: 44번 (Wildcard Matching) [JAVA] 문제 링크 https://leetcode.com/problems/wildcard-matching/ Wildcard Matching - LeetCode Wildcard Matching - Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: * '?' Matches any single character. * '*' Matches any sequence of characters (including the empty sequence). The matchi leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. dp용 이차원 배열 선언 (s의 길이+..
LeetCode: 41번 (First Missing Positive) [JAVA] 문제 링크 https://leetcode.com/problems/first-missing-positive/ First Missing Positive - LeetCode First Missing Positive - Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an algorithm that runs in O(n) time and uses constant extra space. Example 1: Input: nums = [1,2,0] Output: 3 Explanation: Th leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 nums 배열을 돌..
LeetCode: 45번 (Jump Game II) [JAVA] 문제 링크 https://leetcode.com/problems/jump-game-ii/ Jump Game II - LeetCode Jump Game II - You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 주어진 nums 배열 길이만큼의 dp 배열 생성 (모든 위..
LeetCode: 43번 (Multiply Strings) [JAVA] 문제 링크 https://leetcode.com/problems/multiply-strings/ Multiply Strings - LeetCode Multiply Strings - Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You must not use any built-in BigInteger library or convert the inputs to integer directly. leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 두 숫자 문자열을 곱하게 되었을 때 값이 저장될..
LeetCode: 42번 (Trapping Rain Water) [JAVA] 문제 링크 https://leetcode.com/problems/trapping-rain-water/ Trapping Rain Water - LeetCode Trapping Rain Water - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1: [https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png] Input: he leetcode.com 풀이 전체적인 풀이 과정은 다음과 같다. 현 위치에서 접하게 되는 왼쪽과 오른..