原文链接: https://leetcode-cn.com/problems/minimum-operations-to-convert-number 英文原文You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and…
标签详情
数组 分类
原文链接: https://leetcode-cn.com/problems/minimized-maximum-of-products-distributed-to-any-store 英文原文You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed …
原文链接: https://leetcode-cn.com/problems/maximum-path-quality-of-a-graph 英文原文There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. Yo…
原文链接: https://leetcode-cn.com/problems/count-common-words-with-one-occurrence 英文原文Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays. Example 1: Input: words1 = ["leetcode","is",…
原文链接: https://leetcode-cn.com/problems/minimum-cost-homecoming-of-a-robot-in-a-grid 英文原文There is an m x n grid, where (0, 0) is the top-left cell and (m - 1, n - 1) is the bottom-right cell. You are given an integer array startPos where startPos = [s…
原文链接: https://leetcode-cn.com/problems/count-fertile-pyramids-in-a-land 英文原文A farmer has a rectangular grid of land with m rows and n columns that can be divided into unit cells. Each cell is either fertile (represented by a 1) or barren (represented…
原文链接: https://leetcode-cn.com/problems/time-needed-to-buy-tickets 英文原文There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed…
原文链接: https://leetcode-cn.com/problems/two-furthest-houses-with-different-colors 英文原文There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] …
原文链接: https://leetcode-cn.com/problems/find-target-indices-after-sorting-array 英文原文You are given a 0-indexed integer array nums and a target element target. A target index is an index i such that nums[i] == target. Return a list of the target indices…
原文链接: https://leetcode-cn.com/problems/k-radius-subarray-averages 英文原文You are given a 0-indexed array nums of n integers, and an integer k. The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all e…
原文链接: https://leetcode-cn.com/problems/removing-minimum-and-maximum-from-array 英文原文You are given a 0-indexed array of distinct integers nums. There is an element in nums that has the lowest value and an element that has the highest value. We call the…
原文链接: https://leetcode-cn.com/problems/deep-dark-fraction 中文题目有一个同学在学习分式。他需要将一个连分数化成最简分数,你能帮助他吗? 连分数是形如上图的分式。在本题中,所有系数都是大于等于0的整数。 输入的cont代表连分数的系数(cont[0]代表上图的a0,以此类推)。返回一个长度为2的数组[n, m],使得连分数的值等于n / m,且n, m最大公约数为1。 示例 1: 输入:cont = [3, 2, 0, 2] 输出:[13,…
原文链接: https://leetcode-cn.com/problems/broken-board-dominoes 中文题目你有一块棋盘,棋盘上有一些格子已经坏掉了。你还有无穷块大小为1 * 2的多米诺骨牌,你想把这些骨牌不重叠地覆盖在完好的格子上,请找出你最多能在棋盘上放多少块骨牌?这些骨牌可以横着或者竖着放。 输入:n, m代表棋盘的大小;broken是一个b * 2的二维数组,其中每个元素代表棋盘上每一个坏掉的格子的位置。 输出:一个整数,代表最多能在棋盘上放的骨牌数。 示例 1: …
原文链接: https://leetcode-cn.com/problems/coin-bonus 中文题目力扣决定给一个刷题团队发LeetCoin作为奖励。同时,为了监控给大家发了多少LeetCoin,力扣有时候也会进行查询。 该刷题团队的管理模式可以用一棵树表示: 团队只有一个负责人,编号为1。除了该负责人外,每个人有且仅有一个领导(负责人没有领导); 不存在循环管理的情况,如A管理B,B管理C,C管理A。 力扣想进行的操作有以下三种: 给团队的一个成员(也可以是负责人)发一定数量的Leet…
原文链接: https://leetcode-cn.com/problems/programmable-robot 中文题目力扣团队买了一个可编程机器人,机器人初始位置在原点(0, 0)。小伙伴事先给机器人输入一串指令command,机器人就会无限循环这条指令的步骤进行移动。指令有两种: U: 向y轴正方向移动一格 R: 向x轴正方向移动一格。 不幸的是,在 xy 平面上还有一些障碍物,他们的坐标用obstacles表示。机器人一旦碰到障碍物就会被损毁。 给定终点坐标(x, y),返回机器人能否…
原文链接: https://leetcode-cn.com/problems/guess-numbers 中文题目小A 和 小B 在玩猜数字。小B 每次从 1, 2, 3 中随机选择一个,小A 每次也从 1, 2, 3 中选择一个猜。他们一共进行三次这个游戏,请返回 小A 猜对了几次? 输入的guess数组为 小A 每次的猜测,answer数组为 小B 每次的选择。guess和answer的长度都等于3。 示例 1: 输入:guess = [1,2,3], answer = [1,2,3] 输出…
原文链接: https://leetcode-cn.com/problems/three-in-one-lcci 英文原文Describe how you could use a single array to implement three stacks. You should implement push(stackNum, value)、pop(stackNum)、isEmpty(stackNum)、peek(stackNum) methods. stackNum is the index…
原文链接: https://leetcode-cn.com/problems/minimum-height-tree-lcci 英文原文Given a sorted (increasing order) array with unique integer elements, write an algo­rithm to create a binary search tree with minimal height. Example: Given sorted array: [-10,-3…
原文链接: https://leetcode-cn.com/problems/rotate-matrix-lcci 英文原文Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? Example 1: Given matrix…
原文链接: https://leetcode-cn.com/problems/zero-matrix-lcci 英文原文Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] …
原文链接: https://leetcode-cn.com/problems/draw-line-lcci 英文原文A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be spl…
原文链接: https://leetcode-cn.com/problems/power-set-lcci 英文原文Write a method to return all subsets of a set. The elements in a set are pairwise distinct. Note: The result set should not contain duplicated subsets. Example: Input: nums = [1,2,3] Output: […
原文链接: https://leetcode-cn.com/problems/color-fill-lcci 英文原文Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fi…
原文链接: https://leetcode-cn.com/problems/pile-box-lcci 英文原文You have a stack of n boxes, with widths wi, depths di, and heights hi. The boxes cannot be rotated and can only be stacked on top of one another if each box in the stack is strictly larger tha…
原文链接: https://leetcode-cn.com/problems/coin-lcci 英文原文Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be la…
原文链接: https://leetcode-cn.com/problems/search-rotate-array-lcci 英文原文Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted i…
原文链接: https://leetcode-cn.com/problems/eight-queens-lcci 英文原文Write an algorithm to print all ways of arranging n queens on an n x n chess board so that none of them share the same row, column, or diagonal. In this case, "diagonal" means all diagonals…
原文链接: https://leetcode-cn.com/problems/magic-index-lcci 英文原文A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of integers, write a method to find a magic index, if one exists, in array A. If not, …
原文链接: https://leetcode-cn.com/problems/sparse-array-search-lcci 英文原文Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string. Example1: Input: words = ["at", "", "", "", "ball", ""…
原文链接: https://leetcode-cn.com/problems/words-frequency-lcci 英文原文Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times? You should implement following methods: WordsFreq…