258711. 도넛과 막대 그래프
·
Algorithm/Programmers
문제https://school.programmers.co.kr/learn/courses/30/lessons/258711 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr제한사항풀이1. indegree, outdegree 맵을 초기화한다.2. 각 그래프 패턴을 특정하는 노드는 확인 후 그래프 패턴 개수를 더한다.3. 더 중요한 핵심은 그래프 패턴을 특정하는 노드 외에는 그냥 넘길 수 있다는 것을 눈치채는 것이라 생각한다.import java.util.*;class Solution { public int[] solution(int[][] edges) { int[] answer = {}; ..
150368. 이모티콘 할인행사
·
Algorithm/Programmers
문제https://school.programmers.co.kr/learn/courses/30/lessons/150368제한사항풀이1. DFS를 사용하여 모든 할인율 조합 생성2. 각 할인 조합에 대해 사용자 구매 시뮬레이션3. 최적의 결과 저장class Solution { static int maxSubscriberCount = 0; static int maxCost = 0; public int[] solution(int[][] users, int[] emoticons) { int[] answer = {}; int[] discountRates = {10, 20, 30, 40}; int[] discountCombination = new int[emoti..
[DP] 91. Decode Ways
·
Algorithm/LeetCode
문제You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping:"1" -> 'A' "2" -> 'B' ... "25" -> 'Y' "26" -> 'Z'However, while decoding the message, you realize that there are many different ways you can decode the message because some codes are contained in other codes ("2" and "5" vs "25").For example, "11106" can be decoded into:"AAJF"..
213. House Robber II
·
Algorithm/LeetCode
문제You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.Gi..
377. Combination Sum IV
·
Algorithm/LeetCode
문제Combination Sum IVGiven an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.The test cases are generated so that the answer can fit in a 32-bit integer.Example 1:Input: nums = [1,2,3], target = 4Output: 7Explanation:The possible combination ways are:(1, 1, 1, 1)(1, 1, 2)(1, 2, 1)(1, 3)(2, 1, 1)(2, 2)(3, 1)Note that di..
1143. Longest Common Subsequence
·
Algorithm/LeetCode
문제Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.For example, "ace" is a subsequence of "abcde".A common subsequence of two str..
139. Word Break
·
Algorithm/LeetCode
문제Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.Note that the same word in the dictionary may be reused multiple times in the segmentation.Example 1:Input: s = "leetcode", wordDict = ["leet","code"]Output: trueExplanation: Return true because "leetcode" can be segmented as "leet code".Examp..
300. Longest Increasing Subsequence
·
Algorithm/LeetCode
문제Given an integer array nums, return the length of the longest strictly increasingsubsequenceExample 1:Input: nums = [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.Example 2:Input: nums = [0,1,0,3,2,3]Output: 4Example 3:Input: nums = [7,7,7,7,7,7,7]Output: 1Constraints:1 104 Solution 1class Solution { public int lengthO..
322. Coin Change
·
Algorithm/LeetCode
문제You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. You may assume that you have an infinite number of each kind of coin. Example 1:Input: coins = ..
70. Climbing Stairs
·
Algorithm/LeetCode
문제You are climbing a staircase. It takes n steps to reach the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 2:Input: n = 3Output: 3Explanation: There are three ways to climb to the top.1 step + 1 step + 1 step1 step + 2 steps2 steps + 1 step링크: https://leetcode.com/problems/climbing-stairs/description/Solutionclass Solution { publ..