原文链接: https://leetcode-cn.com/problems/robot-in-a-grid-lcci 英文原文Imagine a robot sitting on the upper left corner of grid with r rows and c columns. The robot can only move in two directions, right and down, but certain cells are "off limits" such tha…
标签详情
数组 分类
原文链接: https://leetcode-cn.com/problems/sorted-merge-lcci 英文原文You are given two sorted arrays, A and B, where A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order. Initially the number of elements in A and…
原文链接: https://leetcode-cn.com/problems/peaks-and-valleys-lcci 英文原文In an array of integers, a "peak" is an element which is greater than or equal to the adjacent integers and a "valley" is an element which is less than or equal to the adjacent inte&sh…
原文链接: https://leetcode-cn.com/problems/hanota-lcci 英文原文In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from…
原文链接: https://leetcode-cn.com/problems/sorted-matrix-search-lcci 英文原文Given an M x N matrix in which each row and each column is sorted in ascending order, write a method to find an element. Example: Given matrix: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19…
原文链接: https://leetcode-cn.com/problems/re-space-lcci 英文原文Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeri…
原文链接: https://leetcode-cn.com/problems/longest-word-lcci 英文原文Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If …
原文链接: https://leetcode-cn.com/problems/smallest-k-lcci 英文原文Design an algorithm to find the smallest K numbers in an array. Example: Input: arr = [1,3,5,7,2,4,6,8], k = 4 Output: [1,2,3,4] Note: 0 <= len(arr) <= 100000 0 <= k <= min(100000, len(arr)) …
原文链接: https://leetcode-cn.com/problems/the-masseuse-lcci 英文原文A popular masseuse receives a sequence of back-to-back appointment requests and is debating which ones to accept. She needs a break between appointments and therefore she cannot accept any …
原文链接: https://leetcode-cn.com/problems/multi-search-lcci 英文原文Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions of all strings in smalls that appear in big, where positions[i] i…
原文链接: https://leetcode-cn.com/problems/missing-number-lcci 英文原文An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time? Note: This problem is slightly …
原文链接: https://leetcode-cn.com/problems/find-longest-subarray-lcci 英文原文Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers. Return the subarray. If there are more than one answer, retur…
原文链接: https://leetcode-cn.com/problems/baby-names-lcci 英文原文Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have m…
原文链接: https://leetcode-cn.com/problems/circus-tower-lcci 英文原文A circus is designing a tower routine consisting of people standing atop one anoth­er's shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than…
原文链接: https://leetcode-cn.com/problems/find-majority-element-lcci 英文原文A majority element is an element that makes up more than half of the items in an array. Given a integers array, find the majority element. If there is no majority element, return -…
原文链接: https://leetcode-cn.com/problems/find-closest-lcci 英文原文You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many t…
原文链接: https://leetcode-cn.com/problems/pairs-with-sum-lcci 英文原文Design an algorithm to find all pairs of integers within an array which sum to a specified value. Example 1: Input: nums = [5,6,5], target = 11 Output: [[5,6]] Example 2: Input: nums = [5…
原文链接: https://leetcode-cn.com/problems/shortest-supersequence-lcci 英文原文You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter arr…
原文链接: https://leetcode-cn.com/problems/missing-two-lcci 英文原文You are given an array with all the numbers from 1 to N appearing exactly once, except for two number that is missing. How can you find the missing number in O(N) time and 0(1) space? You ca…
原文链接: https://leetcode-cn.com/problems/max-black-square-lcci 英文原文Imagine you have a square matrix, where each cell (pixel) is either black or white Design an algorithm to find the maximum subsquare such that all four borders are filled with black pix…
原文链接: https://leetcode-cn.com/problems/max-submatrix-lcci 英文原文Given an NxM matrix of positive and negative integers, write code to find the submatrix with the largest possible sum. Return an array [r1, c1, r2, c2], where r1, c1 are the row number and…
原文链接: https://leetcode-cn.com/problems/t9-lcci 英文原文On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0 - 4 letters. Implement an algo­rithm to…
原文链接: https://leetcode-cn.com/problems/sum-swap-lcci 英文原文Given two arrays of integers, find a pair of values (one value from each array) that you can swap to give the two arrays the same sum. Return an array, where the first element is the element in…
原文链接: https://leetcode-cn.com/problems/word-rectangle-lcci 英文原文Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms …
原文链接: https://leetcode-cn.com/problems/langtons-ant-lcci 英文原文An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially. At each step, it does the following: (1) At a white square, flip…
原文链接: https://leetcode-cn.com/problems/na-ying-bi 英文原文 中文题目桌上有 n 堆力扣币,每堆的数量保存在数组 coins 中。我们每次可以选择任意一堆,拿走其中的一枚或者两枚,求拿完所有力扣币的最少次数。 示例 1: 输入:[4,2,1] 输出:4 解释:第一堆力扣币最少需要拿 2 次,第二堆最少需要拿 1 次,第三堆最少需要拿 1 次,总共 4 次即可拿完。 示例 2: 输入:[2,3,10] 输出:8 限制: 1 <= n <= 4 1 <…
原文链接: https://leetcode-cn.com/problems/ju-qing-hong-fa-shi-jian 英文原文 中文题目在战略游戏中,玩家往往需要发展自己的势力来触发各种新的剧情。一个势力的主要属性有三种,分别是文明等级(C),资源储备(R)以及人口数量(H)。在游戏开始时(第 0 天),三种属性的值均为 0。 随着游戏进程的进行,每一天玩家的三种属性都会对应增加,我们用一个二维数组 increase 来表示每天的增加情况。这个二维数组的每个元素是一个长度为 3 的一维…
原文链接: https://leetcode-cn.com/problems/er94lq 英文原文 中文题目秋日市集上,魔术师邀请小扣与他互动。魔术师的道具为分别写有数字 `1~N` 的 `N` 张卡牌,然后请小扣思考一个 `N` 张卡牌的排列 `target`。 魔术师的目标是找到一个数字 k(k >= 1),使得初始排列顺序为 1~N 的卡牌经过特殊的洗牌方式最终变成小扣所想的排列 target,特殊的洗牌方式为: 第一步,魔术师将当前位于 偶数位置 的卡牌(下标自 1 开始),…
原文链接: https://leetcode-cn.com/problems/qie-fen-shu-zu 英文原文 中文题目给定一个整数数组 nums ,小李想将 nums 切割成若干个非空子数组,使得每个子数组最左边的数和最右边的数的最大公约数大于 1 。为了减少他的工作量,请求出最少可以切成多少个子数组。 示例 1: 输入:nums = [2,3,3,2,3,3] 输出:2 解释:最优切割为 [2,3,3,2] 和 [3,3] 。第一个子数组头尾数字的最大公约数为 2 ,第二个子数组头尾数…
原文链接: https://leetcode-cn.com/problems/qi-wang-ge-shu-tong-ji 英文原文 中文题目某互联网公司一年一度的春招开始了,一共有 n 名面试者入选。每名面试者都会提交一份简历,公司会根据提供的简历资料产生一个预估的能力值,数值越大代表越有可能通过面试。 小 A 和小 B 负责审核面试者,他们均有所有面试者的简历,并且将各自根据面试者能力值从大到小的顺序浏览。由于简历事先被打乱过,能力值相同的简历的出现顺序是从它们的全排列中等可能地取一个。现在…