목록MJ (709)
MJay
841. Keys and Rooms Medium 61152 FavoriteShare There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2,..., N-1, and each room may have some keys to access the next room. Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [0, 1,..., N-1] where N = rooms.length. A key rooms[i][j] = v opens the room with number v. Initially, a..
1046. Last Stone Weight Easy 23714FavoriteShare We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest rocks and smash them together. Suppose the stones have weights x and y with x
1221. Split a String in Balanced Strings Easy 9660 FavoriteShare Balanced strings are those who have an equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. Example 1: Input: s = "RLRRLLRLRL" Output: 4 Explanation: s can be split into "RL", "RRLL", "RL", "RL", each substring..
1043. Partition Array for Maximum Sum Medium 32138 FavoriteShare Given an integer array A, you partition the array into (contiguous) subarrays of length at most K. After partitioning, each subarray has its values changed to become the maximum value of that subarray. Return the largest sum of the given array after partitioning. Example 1: Input: A = [1,15,7,9,2,5,10], K = 3 Output: 84 Explanation..
270. Closest Binary Search Tree Value Easy 48536FavoriteShare Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Note: Given target value is a floating point. You are guaranteed to have only one unique value in the BST that is closest to the target. Example: Input: root = [4,2,5,1,3], target = 3.714286 4 / \ 2 5 / \ 1 3 Output: 4 lam..
Given a square array of integers A, we want the minimum sum of a falling path through A. A falling path starts at any element in the first row and chooses one element from each row. The next row's choice must be in a column that is different from the previous row's column by at most one. Example 1: Input: [[1,2,3],[4,5,6],[7,8,9]] Output: 12 Explanation: The possible falling paths are: [1,4,7], ..
For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such that: For every i < j, there is no k with i < k < j such that A[k] * 2 = A[i] + A[j]. Given N, return any beautiful array A. (It is guaranteed that one exists.) Example 1: Input: 4 Output: [2,1,4,3] Example 2: Input: 5 Output: [3,1,2,5,4] Note: 1
959. Regions Cut By Slashes Medium 42588FavoriteShare In a N x N grid composed of 1 x 1 squares, each 1 x 1 square consists of a /, \, or blank space. These characters divide the square into contiguous regions. (Note that backslash characters are escaped, so a \ is represented as "\\".) Return the number of regions. Example 1: Input: [ " /", "/ " ] Output: 2 Explanation: The 2x2 grid is as follo..
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones. The total number of stones is odd, so there are no ties. Alex and Lee take turns, with Alex starting first. Each turn, a player takes the entire pile of stones from either the ..
Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to end with the most stones. The total number of stones is odd, so there are no ties. Alex and Lee take turns, with Alex starting first. Each turn, a player takes the entire pile of stones from either the ..