原文链接: https://leetcode-cn.com/problems/rotate-list 英文原文Given the head of a linked list, rotate the list to the right by k places. Example 1: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Example 2: Input: head = [0,1,2], k = 4 Output: [2,0,1] …
分类详情
中等 分类
原文链接: https://leetcode-cn.com/problems/unique-paths 英文原文A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach t…
原文链接: https://leetcode-cn.com/problems/unique-paths-ii 英文原文A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reac…
原文链接: https://leetcode-cn.com/problems/minimum-path-sum 英文原文Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or …
原文链接: https://leetcode-cn.com/problems/simplify-path 英文原文Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file …
原文链接: https://leetcode-cn.com/problems/set-matrix-zeroes 英文原文Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's, and return the matrix. You must do it in place. Example 1: Input: matrix = [[1,1,1],[1,0,1],[…
原文链接: https://leetcode-cn.com/problems/sort-colors 英文原文Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use t…
原文链接: https://leetcode-cn.com/problems/search-a-2d-matrix 英文原文Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first integer o…
原文链接: https://leetcode-cn.com/problems/combinations 英文原文Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. Example 1: Input: n = 4, k = 2 Output: [ [2,4], [3,4], …
原文链接: https://leetcode-cn.com/problems/subsets 英文原文Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Example 1: Input: n…
原文链接: https://leetcode-cn.com/problems/word-search 英文原文Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells ar…
原文链接: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii 英文原文Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice. The relative order of t…
原文链接: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii 英文原文Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted…
原文链接: https://leetcode-cn.com/problems/partition-list 英文原文Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the…
原文链接: https://leetcode-cn.com/problems/gray-code 英文原文An n-bit gray code sequence is a sequence of 2n integers where: Every integer is in the inclusive range [0, 2n - 1], The first integer is 0, An integer appears no more than once in the sequence, Th…
原文链接: https://leetcode-cn.com/problems/subsets-ii 英文原文Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. Example…
原文链接: https://leetcode-cn.com/problems/decode-ways 英文原文A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped t…
原文链接: https://leetcode-cn.com/problems/restore-ip-addresses 英文原文A valid IP address consists of exactly four integers separated by single dots. Each integer is between 0 and 255 (inclusive) and cannot have leading zeros. For example, "0.1.2.201" and "…
原文链接: https://leetcode-cn.com/problems/unique-binary-search-trees-ii 英文原文Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order. Examp…
原文链接: https://leetcode-cn.com/problems/unique-binary-search-trees 英文原文Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. Example 1: Input: n = 3 Output: 5 E…
原文链接: https://leetcode-cn.com/problems/interleaving-string 英文原文Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. An interleaving of two strings s and t is a configuration where they are divided into non-empty su…
原文链接: https://leetcode-cn.com/problems/validate-binary-search-tree 英文原文Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys l…
原文链接: https://leetcode-cn.com/problems/recover-binary-search-tree 英文原文You are given the root of a binary search tree (BST), where the values of exactly two nodes of the tree were swapped by mistake. Recover the tree without changing its structure. Ex…
原文链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal 英文原文Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). Example 1: Input: root = [3,9,20,null,nul…
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal 英文原文Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the s…
原文链接: https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal 英文原文Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of t…
原文链接: https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii 英文原文Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root). Example 1:…
原文链接: https://leetcode-cn.com/problems/convert-sorted-list-to-binary-search-tree 英文原文Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary …
原文链接: https://leetcode-cn.com/problems/path-sum-ii 英文原文Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of th…
原文链接: https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node 英文原文You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct…