[LeetCode] 2466. Count Ways To Build Good Strings (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:Append the character '0' zero times.Append the character '1' one times.This can be performed any number of times.A good string is a string constructed by the above process having a length between low and high (inclusive).R..
[LeetCode] 3286. Find a Safe Walk Through a Grid (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given an m x n binary matrix grid and an integer health. You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1). You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive. Cells (i, j) with grid[i][j] = 1 are considered unsafe and reduce your health by 1. Return t..
[LeetCode] 1122. Relative Sort Array (Python)
·
알고리즘/LeetCode
난이도: Easy 문제 설명Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that do not appear in arr2 should be placed at the end of arr1 in ascending order. 문제 예제Example 1:Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]Output..
[LeetCode] 1014. Best Sightseeing Pair (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them. The score of a pair (i ) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them. Return the maximum score of a pair of sightseeing s..
[LeetCode] 494. Target Sum (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given an integer array nums and an integer target.You want to build an expression out of nums by adding one of the symbols '+' and '-' before each integer in nums and then concatenate all the integers.For example, if nums = [2, 1], you can add a '+' before 2 and a '-' before 1 and concatenate them to build the expression "+2-1".Return the number of different expressions ..
[LeetCode] 1962. Remove Stones to Minimize the Total (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from it.Notice that you can apply the operation on the same pile more than once. Return the minimum possible total number of stones rema..