原文链接: https://leetcode-cn.com/problems/shift-2d-grid 英文原文Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to gri…
标签详情
模拟 分类
原文链接: https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game 英文原文Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are: Players take turns placing characters into empty squares ' '. The first player A …
原文链接: https://leetcode-cn.com/problems/print-words-vertically 英文原文Given a string s. Return all the words vertically in the same order in which they appear in s. Words are returned as a list of strings, complete with spaces when is necessary. (Trailin…
原文链接: https://leetcode-cn.com/problems/queries-on-a-permutation-with-key 英文原文Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules: In the be…
原文链接: https://leetcode-cn.com/problems/build-an-array-with-stack-operations 英文原文Given an array target and an integer n. In each iteration, you will read a number from list = {1,2,3..., n}. Build the target array using the following operations: Push: …
原文链接: https://leetcode-cn.com/problems/last-moment-before-all-ants-fall-out-of-a-plank 英文原文We have a wooden plank of the length n units. Some ants are walking on the plank, each ant moves with speed 1 unit per second. Some of the ants move to the lef…
原文链接: https://leetcode-cn.com/problems/water-bottles 英文原文Given numBottles full water bottles, you can exchange numExchange empty water bottles for one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Ret…
原文链接: https://leetcode-cn.com/problems/find-the-winner-of-an-array-game 英文原文Given an integer array arr of distinct integers and an integer k. A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of…
原文链接: https://leetcode-cn.com/problems/most-visited-sector-in-a-circular-track 英文原文Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the ma…
原文链接: https://leetcode-cn.com/problems/find-latest-group-of-size-m 英文原文Given an array arr that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero. At each step i (assuming b…
原文链接: https://leetcode-cn.com/problems/design-parking-system 英文原文Design a parking system for a parking lot. The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size. Implement the ParkingSy…
原文链接: https://leetcode-cn.com/problems/maximum-profit-of-operating-a-centennial-wheel 英文原文You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas …
原文链接: https://leetcode-cn.com/problems/get-maximum-in-generated-array 英文原文You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n…
原文链接: https://leetcode-cn.com/problems/find-the-student-that-will-replace-the-chalk 英文原文There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number…
原文链接: https://leetcode-cn.com/problems/cyclically-rotating-a-grid 英文原文You are given an m x n integer matrix grid, where m and n are both even integers, and an integer k. The matrix is composed of several layers, which is shown in the below image, …
原文链接: https://leetcode-cn.com/problems/build-array-from-permutation 英文原文Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based perm…
原文链接: https://leetcode-cn.com/problems/sum-of-digits-of-string-after-convert 英文原文You are given a string s consisting of lowercase English letters, and an integer k. First, convert s into an integer by replacing each letter with its position in the al…
原文链接: https://leetcode-cn.com/problems/convert-1d-array-into-2d-array 英文原文You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n column…
原文链接: https://leetcode-cn.com/problems/final-value-of-variable-after-performing-operations 英文原文There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decremen…
原文链接: https://leetcode-cn.com/problems/find-missing-observations 英文原文You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately…
原文链接: https://leetcode-cn.com/problems/number-of-valid-move-combinations-on-chessboard 英文原文There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the ty…
原文链接: https://leetcode-cn.com/problems/walking-robot-simulation-ii 英文原文A width x height grid is on an XY-plane with the bottom-left cell at (0, 0) and the top-right cell at (width - 1, height - 1). The grid is aligned with the four cardinal direction…
原文链接: 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/decode-the-slanted-ciphertext 英文原文A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows. originalText is place…
原文链接: 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/programmable-robot 中文题目力扣团队买了一个可编程机器人,机器人初始位置在原点(0, 0)。小伙伴事先给机器人输入一串指令command,机器人就会无限循环这条指令的步骤进行移动。指令有两种: U: 向y轴正方向移动一格 R: 向x轴正方向移动一格。 不幸的是,在 xy 平面上还有一些障碍物,他们的坐标用obstacles表示。机器人一旦碰到障碍物就会被损毁。 给定终点坐标(x, y),返回机器人能否…
原文链接: https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof 中文题目输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。 示例 1: 输入:matrix = [[1,2,3],[4,5,6],[7,8,9]] 输出:[1,2,3,6,9,8,7,4,5] 示例 2: 输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] 输出:[1,2,3,4,8,12,11,1…
原文链接: https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof 中文题目输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如,序列 {1,2,3,4,5} 是某栈的压栈序列,序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列,但 {4,3,5,1,2} 就不可能是该压栈序列的弹出序列。 示例 1: 输入:pushed = [1,2,3,4,…
原文链接: 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/er94lq 英文原文 中文题目秋日市集上,魔术师邀请小扣与他互动。魔术师的道具为分别写有数字 `1~N` 的 `N` 张卡牌,然后请小扣思考一个 `N` 张卡牌的排列 `target`。 魔术师的目标是找到一个数字 k(k >= 1),使得初始排列顺序为 1~N 的卡牌经过特殊的洗牌方式最终变成小扣所想的排列 target,特殊的洗牌方式为: 第一步,魔术师将当前位于 偶数位置 的卡牌(下标自 1 开始),…