原文链接: 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/largest-rectangle-in-histogram 英文原文Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram. Example …
原文链接: https://leetcode-cn.com/problems/maximal-rectangle 英文原文Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example 1: Input: matrix = [["1","0","1","0","0"],["1","0","1"…
原文链接: https://leetcode-cn.com/problems/merge-sorted-array 英文原文You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1…
原文链接: 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/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/convert-sorted-array-to-binary-search-tree 英文原文Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a…
原文链接: https://leetcode-cn.com/problems/pascals-triangle 英文原文Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: Example 1: Input: numRows…
原文链接: https://leetcode-cn.com/problems/pascals-triangle-ii 英文原文Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: Exam…
原文链接: https://leetcode-cn.com/problems/triangle 英文原文Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, y…
原文链接: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock 英文原文You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choo…
原文链接: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii 英文原文You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transacti…
原文链接: https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii 英文原文You are given an integer array prices where prices[i] is the price of a given stock on the ith day. On each day, you may decide to buy and/or sell the stock. You can only h…
原文链接: https://leetcode-cn.com/problems/longest-consecutive-sequence 英文原文Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: nu…
原文链接: https://leetcode-cn.com/problems/surrounded-regions 英文原文Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded r…
原文链接: https://leetcode-cn.com/problems/gas-station 英文原文There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith…
原文链接: https://leetcode-cn.com/problems/candy 英文原文There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: Each…
原文链接: https://leetcode-cn.com/problems/single-number 英文原文Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with a linear runtime complexity and use only constant …
原文链接: https://leetcode-cn.com/problems/evaluate-reverse-polish-notation 英文原文Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, and /. Each operand may be an integer or another expression. Note that…
原文链接: https://leetcode-cn.com/problems/maximum-product-subarray 英文原文Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. It is guaranteed that the answer will fit in …
原文链接: https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array 英文原文Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [4,5,6,7,0,1,2] if it…
原文链接: https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii 英文原文Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become: [4,5,6,7,0,1,4] if…
原文链接: https://leetcode-cn.com/problems/find-peak-element 英文原文A peak element is an element that is strictly greater than its neighbors. Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, retur…