17. Letter Combinations of a Phone Number
·
Algorithm/LeetCode
문제https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/제한사항풀이 import java.util.*; class Solution { public List letterCombinations(String digits) { Map> map = new HashMap(); if(digits.equals("")) return new ArrayList(); map.computeIfAbsent('2', k-> List.of("a", "b", "c")); map.computeIfAbse..
403. Frog Jump
·
Algorithm/LeetCode
문제https://leetcode.com/problems/frog-jump/description/제한 사항풀이class Solution { public boolean canCross(int[] stones) { Map map = new HashMap(); int n = stones.length; // 빠른 조회를 위해 HashMap에 돌 위치 저장 for(int i = 0 ; i회고DP 문제이면서도 제한 조건의 범위가 크지 않아서 O(n^2)을 허용하는 문제였다. DP 배열을 정의하는 것이 쉽지 않았다. 그리고 최대 점프 길이 반드시 알아야 하는 문제였다. k는 1부터 시작해서 k-1, k, k+1 중 하나의 길이만큼 점프를 한다. 점프한 만큼의 ..
[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..