[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..
143. Reorder List
·
Algorithm/LeetCode
문제You are given the head of a singly linked-list. The list can be represented as:L0 → L1 → … → Ln - 1 → LnReorder the list to be on the following form:L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …You may not modify the values in the list's nodes. Only nodes themselves may be changed.링크: https://leetcode.com/problems/reorder-listSolution 1class Solution { public void reorderList(ListNode head) { if..
200. Number of Islands
·
Algorithm/LeetCode
문제전형적인 bfs 탐색 문제였다. 0은 물, 1은 땅을 의미하는 그래프 배열이 주어진다. 땅이 근접하게 모여 있으면 하나의 섬이다. 섬의 갯수를 요구하는 문제였다.링크: https://leetcode.com/problems/number-of-islands/description/Solutionclass Solution { static int[][] dirArray = {{-1,0},{1,0},{0,-1},{0,1}}; public int numIslands(char[][] grid) { int m = grid.length; int n = grid[0].length; boolean[][]visited = new boolean[m][n]; int ..