题库chevron_right分类chevron_right模拟
smart_toy

模拟

171 道题目
简单: 75中等: 85困难: 11

模拟 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
43

字符串相乘

Multiply Strings requires simulating integer multiplication using only string operations without direct numeric conversi…

中等
54

螺旋矩阵

Given an m x n matrix, return all elements in spiral order starting from the top-left corner.

中等
59

螺旋矩阵 II

Generate a spiral matrix of size n x n, filled with elements from 1 to n² in spiral order, for interview-focused solving…

中等
67

二进制求和

Add Binary involves summing two binary strings and returning the result as a binary string using math and string manipul…

简单
68

文本左右对齐

Text Justification requires packing words into lines to match a specified width, ensuring even distribution of spaces.

困难
258

各位相加

Add Digits involves repeatedly summing digits of a number until a single digit is obtained.

简单
289

生命游戏

Solve the Game of Life by updating each cell based on its eight neighbors using Array and Matrix simulation patterns eff…

中等
412

Fizz Buzz

Generate a list from 1 to n replacing multiples of 3 with Fizz, 5 with Buzz, and both with FizzBuzz efficiently.

简单
415

字符串相加

Given two non-negative integers as strings, sum them and return the result as a string without converting to integers di…

简单
495

提莫攻击

Compute the total poisoned time Ashe experiences from Teemo's attacks using an array-based simulation approach efficient…

简单
498

对角线遍历

Traverse a matrix diagonally and return all elements in the specific zig-zag order required by the problem pattern.

中等
537

复数乘法

This problem requires multiplying two complex numbers, given in string form, and returning the result in the same format…

中等
566

重塑矩阵

Reshape the Matrix involves transforming a 2D matrix into a new matrix with the same elements in row-major order, follow…

简单
592

分数加减运算

Solve fraction addition and subtraction by handling expressions, calculating results, and simplifying fractions to irred…

中等
640

求解方程

Solve the equation for the variable 'x' and determine its value or state if there is no solution or infinite solutions.

中等
657

机器人能否返回原点

Judge whether a robot returns to the origin after a sequence of moves using string manipulation and simulation.

简单
682

棒球比赛

Simulate baseball score operations using a stack-based approach to compute the final score after all operations.

简单
735

小行星碰撞

Determine the final positions of moving asteroids using a stack-based simulation for efficient collision resolution in l…

中等
749

隔离病毒

Contain Virus involves using array-based Depth-First Search to contain viral spread by building walls around infected re…

困难
832

翻转图像

Flip each row of a binary matrix horizontally and invert its values efficiently using a two-pointer scanning approach.

简单
844

比较含退格的字符串

Compare two strings after processing backspaces using efficient two-pointer scanning and careful invariant tracking to e…

简单
867

转置矩阵

Transpose Matrix problem requires flipping a matrix's rows and columns to return the transposed version.

简单
874

模拟行走机器人

The Walking Robot Simulation problem involves moving a robot in an infinite grid and calculating its furthest distance f…

中等
885

螺旋矩阵 III

Solve the Spiral Matrix III problem by simulating the movement across a matrix with specific constraints on direction an…

中等
946

验证栈序列

Determine if a sequence of push and pop operations can produce the given popped array using a stack-based state approach…

中等
950

按递增顺序显示卡牌

Determine the initial deck order to reveal cards in strictly increasing order using queue-driven simulation logic.

中等
985

查询后的偶数和

Efficiently update an integer array based on queries and compute the sum of even numbers after each modification using s…

中等
999

可以被一步捕获的棋子数

This problem involves finding the number of pawns a rook can capture on a chessboard, considering obstacles like bishops…

简单
1006

笨阶乘

Compute the clumsy factorial of a number using a fixed rotation of multiply, divide, add, and subtract operations effici…

中等
1041

困于环中的机器人

Determine if a robot following a repeated instruction sequence stays within a bounded circle using math and string simul…

中等
1094

拼车

Determine if a car can handle multiple trips without exceeding its capacity using array sorting and event simulation tec…

中等
1103

分糖果 II

Distribute candies to people in a way that follows a mathematical pattern, ensuring the distribution is correct.

简单
1222

可以攻击国王的皇后

Identify all black queens on an 8x8 chessboard that can attack the white king using array and matrix simulation techniqu…

中等
1252

奇数值单元格的数目

This problem involves updating a matrix based on given indices and counting cells with odd values afterward.

简单
1260

二维网格迁移

Shift 2D Grid requires shifting elements of a matrix by a given number of times, simulating step-by-step movement.

简单
1275

找出井字棋的获胜者

Determine the winner of a Tic Tac Toe game by scanning moves and using hash lookups for rows, columns, and diagonals eff…

简单
1324

竖直打印单词

Transform a string into vertical columns by arranging each word character in array positions while trimming trailing spa…

中等
1389

按既定顺序创建目标数组

Learn how to efficiently create a target array by inserting elements at specified indices using array simulation techniq…

简单
1404

将二进制表示减到 1 的步骤数

Determine the number of steps to reduce a binary representation of a number to 1 by following specific rules.

中等
1409

查询带键的排列

This problem involves processing queries on a permutation using an array and binary indexed tree for efficient results.

中等
1441

用栈操作构建数组

Simulate stack operations to match a target array while processing numbers from 1 to n.

中等
1503

所有蚂蚁掉下来前的最后一刻

This problem involves simulating ant movement on a plank to determine the last moment before all ants fall off.

中等
1518

换水问题

Maximize the number of water bottles you can drink by simulating the exchange process between full and empty bottles.

简单
1535

找出数组游戏的赢家

Determine the integer that wins an array game by achieving k consecutive victories through simulated pairwise comparison…

中等
1545

找出第 N 个二进制字符串中的第 K 位

Determine the k-th bit in the n-th binary string using a recursive construction that inverts and reverses previous strin…

中等
1560

圆形赛道上经过次数最多的扇区

Determine which sectors on a circular track are visited most frequently using array and simulation techniques efficientl…

简单
1562

查找大小为 M 的最新分组

Determine the latest step where a contiguous group of ones of exact length m exists using array scanning and hash tracki…

中等
1583

统计不开心的朋友

Determine the number of unhappy friends in paired arrangements using array-based simulation for preference violations.

中等
1599

经营摩天轮的最大利润

Maximize the profit from operating a Centennial Wheel by determining the optimal number of rotations based on customer a…

中等
1603

设计停车系统

Implement a class to manage a parking lot with fixed slots for big, medium, and small cars, tracking occupancy efficient…

简单
1646

获取生成数组中的最大值

Compute the maximum value in a generated array using defined recurrence rules, leveraging array simulation techniques ef…

简单
1680

连接连续二进制数字

Calculate the decimal value of concatenated binary numbers from 1 to n using efficient bit manipulation techniques.

中等
1688

比赛中的配对次数

Calculate the total matches in a tournament by simulating rounds and applying simple math rules for advancing teams.

简单
1700

无法吃午餐的学生数量

Simulate a queue of students with sandwich preferences and determine how many can't eat based on available sandwiches.

简单
1701

平均等待时间

Compute the average waiting time for customers using array traversal and simulation of a single chef processing orders s…

中等
1706

球会落何处

Determine where each ball exits a diagonal board grid or if it gets stuck, using matrix simulation with careful traversa…

中等
1801

积压订单中的订单总数

Determine the total number of unfulfilled buy and sell orders using heaps to simulate backlog processing efficiently in …

中等
1806

还原排列的最少操作步数

Find the minimum number of operations to reinitialize a permutation of size n using specific operations.

中等
1823

找出游戏的获胜者

Find the winner of a circular game by simulating the elimination process with a queue-driven approach.

中等
1860

增长的内存泄露

Solve Incremental Memory Leak by simulating each second carefully and using math to reason about the crash time bound.

中等
1894

找到需要补充粉笔的学生编号

Identify the first student who will run out of chalk using a simulation with prefix sums and binary search.

中等
1910

删除一个字符串中所有出现的给定子字符串

Remove all occurrences of a specified substring from a string using efficient stack-based state management.

中等
1914

循环轮转矩阵

This problem requires cyclically rotating a grid by rotating each layer of the matrix counter-clockwise for a specified …

中等
1920

基于排列构建数组

The problem asks to build an array from a given permutation using an efficient approach.

简单
1929

数组串联

This problem asks you to create an array of double the size, where each element is repeated twice in sequence.

简单
1945

字符串转化后的各位数字之和

Convert a lowercase string into digits and repeatedly sum them k times using a direct string plus simulation approach.

简单
2011

执行操作后的变量值

Compute the final value of X by simulating each string operation in the array sequentially with careful tracking.

简单
2022

将一维数组转变成二维数组

Convert a 1D integer array into a structured 2D array with specified rows and columns using all elements sequentially.

简单
2028

找出缺失的观测数据

Given a set of dice rolls, calculate the missing observations based on the mean and return them or determine if it's imp…

中等
2043

简易银行系统

Design a simple bank system that processes transactions like withdrawals, deposits, and transfers while managing account…

中等
2056

棋盘上有效移动组合的数目

Given a set of pieces on a chessboard, calculate the number of valid move combinations without overlap using backtrackin…

困难
2069

模拟行走机器人 II

The Walking Robot Simulation II problem challenges you to simulate robot movements and track its position and direction …

中等
2073

买票需要的时间

Calculate the total time for a specific person to buy all their tickets using queue-driven state processing.

简单
2075

解码斜向换位密码

Decode the Slanted Ciphertext problem requires decoding a slanted cipher using string manipulation and simulation based …

中等
2079

给植物浇水

Simulate watering plants while managing a watering can's capacity, considering distance and refills.

中等
2105

给植物浇水 II

Simulate watering a row of plants with Alice and Bob using two-pointer scanning, tracking refills precisely for each ste…

中等
2109

向字符串添加空格

Learn to efficiently insert spaces in a string using two-pointer scanning with invariant tracking in linear time.

中等
2120

执行所有后缀指令

Simulate robot moves from every instruction index on an n x n grid, counting valid steps without leaving boundaries.

中等
2138

将字符串拆分为若干长度为 k 的组

Divide a string into equal groups of size k, using a fill character to complete the last group if needed.

简单
2149

按符号重排数组

Rearrange an array by alternating positive and negative integers using a two-pointer approach with invariant tracking.

中等
2154

将找到的值乘以 2

The "Keep Multiplying Found Values by Two" problem involves repeatedly multiplying a number by two if it is found in an …

简单
2161

根据给定数字划分数组

Rearrange an array around a pivot while maintaining relative order using a two-pointer scanning approach efficiently.

中等
2169

得到 0 的操作数

Simulate operations on two integers until one becomes zero, counting how many steps it takes to achieve the result.

简单
2177

找到和为给定整数的三个连续整数

Given a number, find three consecutive integers that sum to it, or return an empty array if no such integers exist.

中等
2180

统计各位数字之和为偶数的整数个数

Solve this Easy Math plus Simulation problem by counting numbers whose digit sums are even up to a given limit efficient…

简单
2181

合并零之间的节点

This problem requires merging nodes between zeros in a linked list by summing up the values between consecutive zeros.

中等
2201

统计可以提取的工件

Count the number of artifacts that can be extracted after excavating specified grid cells.

中等
2211

统计道路上的碰撞次数

Count Collisions on a Road is a problem where you calculate the number of car collisions based on their movements in a s…

中等
2221

数组的三角和

The problem asks for calculating the triangular sum of an array through repeated pairwise summation.

中等
2243

计算字符串的数字和

Learn how to repeatedly sum digit groups in a string until its length is at most k using string simulation techniques.

简单
2257

统计网格图中没有被保卫的格子数

Solve Count Unguarded Cells in the Grid by marking guard sight lines across a blocked matrix and counting untouched empt…

中等
2293

极大极小游戏

The Min Max Game problem requires simulating an array reduction process to find the last remaining number.

简单
2295

替换数组中的元素

Replace Elements in an Array involves applying a series of operations to replace values in an array with new ones based …

中等
2296

设计一个文本编辑器

Design a text editor that supports text manipulation and cursor navigation operations efficiently with linked-list-based…

困难
2303

计算应缴税款总额

Calculate the total tax owed by iterating through sorted brackets and applying each rate incrementally to your income.

简单
2326

螺旋矩阵 IV

In this problem, you need to generate a matrix filled with values from a linked list in a spiral order.

中等
2327

知道秘密的人数

Calculate how many people know a secret over n days using state transition dynamic programming and careful simulation of…

中等
2352

相等行列对

Identify all pairs of rows and columns in a square matrix that contain identical elements in the same sequence efficient…

中等
2357

使数组中所有元素都等于零

Minimize operations to make all array elements zero by subtracting equal amounts in each operation.

简单
2365

任务调度器 II

Complete tasks in the optimal number of days by considering breaks and task type constraints.

中等
2380

二进制字符串重新安排顺序需要的时间

Calculate the exact seconds required to convert all 01 pairs into 10 in a binary string using state transitions.

中等
2390

从字符串中移除星号

Remove all stars from a string by simulating the removal process using a stack to manage characters and stars efficientl…

中等
2402

会议室 III

Determine which meeting room holds the most meetings by simulating room assignments with precise time tracking.

困难
2460

对数组执行操作

Transform an array by applying adjacent doubling operations and shifting zeros efficiently using two-pointer scanning te…

简单
2462

雇佣 K 位工人的总代价

Optimize the total cost of hiring exactly k workers using a two-pointer approach with invariant tracking and priority qu…

中等
2482

行和列中一和零的差值

This problem requires computing a difference matrix based on the ones and zeros in each row and column of a binary matri…

中等
2500

删除每行中的最大值

Calculate the total of removed maximum values from each row of a matrix, iterating until all columns are deleted efficie…

简单
2502

设计内存分配器

Design a memory allocator that simulates allocation and deallocation of memory blocks.

中等
2507

使用质因数之和替换后可以取到的最小值

Replace a number with the sum of its prime factors until it stabilizes, and return the smallest value.

中等
2532

过桥的时间

Time to Cross a Bridge involves simulating worker movements using arrays and heaps to determine when the last worker cro…

困难
2549

统计桌面上的不同数字

Compute the number of distinct integers generated on a board using repeated modulo operations over a long sequence of da…

简单
2553

分割数组中数字的数位

Given an array of positive integers, separate each integer into its individual digits while preserving the original orde…

简单
2558

从数量最多的堆取走礼物

Take Gifts From the Richest Pile uses a heap to simulate the process of taking gifts from the richest pile over a number…

简单
2562

找出数组的串联值

Compute the array concatenation value efficiently using two-pointer scanning while maintaining a running total of concat…

简单
2582

递枕头

Pass the Pillow simulates the process of passing an item through a line of people, adjusting the direction based on time…

简单
2593

标记所有元素后数组的分数

The problem involves marking elements in an array and calculating the score based on adjacent elements.

中等
2596

检查骑士巡视方案

Validate a knight's movement configuration on an n x n chessboard to check if it forms a valid Knight's Tour.

中等
2660

保龄球游戏的获胜者

Simulate a bowling game to determine the winner based on hit pins per turn for two players.

简单
2679

矩阵中的和

Calculate the maximum score by repeatedly removing the largest elements from each row of a 2D matrix efficiently using s…

中等
2682

找出转圈游戏输家

Simulate a ball-passing game around a circle using array scanning and hash lookup to find friends who never receive the …

简单
2696

删除子串后的字符串最小长度

Determine the smallest string length after repeatedly removing AB or CD substrings using stack-based simulation techniqu…

简单
2717

半有序排列

Find the minimum number of operations to convert a permutation into a semi-ordered permutation where 1 is first and n is…

简单
2739

总行驶距离

Calculate the maximum distance a truck can travel using main and additional fuel tanks with controlled transfers.

简单
2744

最大字符串配对数目

Find the maximum number of pairs of distinct strings from an array where one string is the reverse of the other.

简单
2751

机器人碰撞

Robot Collisions involves simulating robot movements and handling collisions with stack-based state management.

困难
2766

重新放置石块

Relocate marbles to new positions in an array by simulating moves, and return sorted occupied positions.

中等
2810

故障键盘

Simulate typing on a faulty keyboard where pressing 'i' reverses the string, requiring careful string manipulation track…

简单
2899

上一个遍历的整数

This problem involves finding the last visited integer for each -1 in a given array by simulating a stack-like behavior.

简单
2946

循环移位后的矩阵相似检查

Determine if a matrix returns to its original state after performing cyclic row shifts k times using array and math patt…

简单
2960

统计已测试设备

Simulate testing devices based on battery percentages to determine how many pass the test operations in sequence.

简单
2961

双模幂运算

Solve the Double Modular Exponentiation problem by applying array manipulation and modular arithmetic to find good indic…

中等
2974

最小数字游戏

The Minimum Number Game involves simulating moves by Alice and Bob on an array, sorting elements and appending them to a…

简单
3028

边界上的蚂蚁

Solve the problem of counting how often an ant returns to a boundary based on the steps described in the input array.

简单
3038

相同分数的最大操作数目 I

Determine the maximum number of operations in an integer array where each operation must produce the same score.

简单
3066

超过阈值的最少操作数 II

Calculate the fewest operations to make every array element exceed a threshold using a min-heap simulation strategy effi…

中等
3069

将元素分配到两个数组中 I

Distribute elements from a distinct integer array into two subarrays using a sequential simulation strategy for optimal …

简单
3072

将元素分配到两个数组中 II

Distribute elements into two arrays based on conditions, utilizing a Binary Indexed Tree for efficient counting and simu…

困难
3080

执行操作标记数组中的元素

Efficiently mark elements in an array based on queries using scanning plus hash lookup to track marked indices and compu…

中等
3100

换水问题 II

Compute the maximum number of water bottles you can drink by simulating exchanges with step-by-step math logic.

中等
3160

所有球里面不同颜色的数目

Efficiently track colors on balls using array scanning and hash lookup to return the count of distinct colors after each…

中等
3168

候诊室中的最少椅子数

Calculate the minimum number of chairs needed in a waiting room using string simulation and event tracking efficiently.

简单
3174

清除数字

Remove all digits from a given string by applying a repeated operation to form the final string without digits.

简单
3175

找到连续赢 K 场比赛的第一位玩家

Determine which player first wins k consecutive games using array simulation logic to track ongoing victories efficientl…

中等
3178

找出 K 秒后拿着球的孩子

Find the child who holds the ball after k seconds of passing in a queue, considering reversals at both ends.

简单
3179

K 秒后第 N 个元素的值

Solve for the N-th value after K seconds by simulating array updates and using prefix sum techniques.

中等
3222

求出硬币游戏的赢家

In this game between Alice and Bob, players must pick coins summing to 115. Alice starts, and the goal is to determine t…

简单
3242

设计相邻元素求和服务

Design a service that computes sums for adjacent and diagonal elements in a 2D grid.

简单
3248

矩阵中的蛇

Solve the Snake in Matrix problem by simulating the snake's movement in a grid based on a series of directional commands…

简单
3264

K 次乘运算后的最终数组 I

Solve the problem of determining the final state of an array after multiple multiplication operations using a priority q…

简单
3266

K 次乘运算后的最终数组 II

Optimize the final state of an array after performing k multiplication operations with priority queues.

困难
3271

哈希分割字符串

Hash Divided String requires splitting a string into equal parts and combining character values modulo 26 to form a new …

中等
3304

找出第 K 个字符 I

Find the K-th character in a progressively built string using math and bit manipulation efficiently.

简单
3324

出现在屏幕上的字符串序列

Simulate Alice typing a target string with a special keyboard that appends letters one by one. Solve using string simula…

中等
3354

使数组元素等于零

Learn how to transform an integer array to zeros using simulation and directional selection efficiently and reliably.

简单
3360

移除石头游戏

Alice and Bob play a game of stone removal. Alice goes first, and the winner is the player who can make a move until the…

简单
3379

转换数组

Simulate operations on a circular array to return a transformed result array following specific rules.

简单
3412

计算字符串的镜像分数

Calculate the mirror score of a string using stack-based state management for matching letters efficiently and accuratel…

中等
3417

跳过交替单元格的之字形遍历

Traverse a 2D grid in a zigzag pattern while skipping alternate cells, focusing on array and matrix manipulation challen…

简单
3433

统计用户被提及情况

Calculate how many times each user is mentioned across MESSAGE events, accounting for offline and online statuses effici…

中等
3461

判断操作后字符串中的数字是否相等 I

Simulate repeated adjacent digit sums modulo 10 until two digits remain, then check whether those final digits match.

简单
3477

水果成篮 II

Determine the number of fruit types that remain unplaced after all allocations in the "Fruits Into Baskets II" problem.

简单
3494

酿造药水需要的最少总时间

This problem involves calculating the minimum time required for wizards to brew potions based on their skills and mana u…

中等
3498

字符串的反转度

Calculate the reverse degree of a string by simulating operations on its characters based on their positions in the alph…

简单
3507

移除最小数对使数组有序 I

This problem asks for the minimum number of operations to make an array non-decreasing by removing pairs of elements.

简单
3510

移除最小数对使数组有序 II

The problem asks to find the minimum number of operations to make an array non-decreasing by removing pairs of elements.

困难
3522

执行指令后的得分

Simulate a series of add and jump instructions on arrays to compute the final score efficiently using array scanning and…

中等
3561

移除相邻字符

This problem focuses on removing adjacent characters in a string using a stack-based approach until no more operations a…

中等
3582

为视频标题生成标签

Transform a video caption into a valid hashtag by simulating capitalization rules and truncation for long words efficien…

简单
3597

分割字符串

Partition a string into unique segments using hash table and string manipulation.

中等
3612

用特殊操作处理字符串 I

Simulate a series of operations on a string to transform it into the desired result using special characters.

中等
3614

用特殊操作处理字符串 II

Solve the problem of processing strings with special operations like '*' and '#' by simulating the rules left-to-right.

困难

关联高频模式

LeetCode 模拟题型题解:171题训练路线