原文链接: https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii 英文原文Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no nex…
分类详情
中等 分类
原文链接: 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-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/sum-root-to-leaf-numbers 英文原文You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 rep…
原文链接: 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/palindrome-partitioning 英文原文Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. A palindrome string is a string that reads …
原文链接: https://leetcode-cn.com/problems/clone-graph 英文原文Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a value (int) and a list (List[Node]) of its neighbors. class…
原文链接: 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/flatten-binary-tree-to-linked-list 英文原文Given the root of a binary tree, flatten the tree into a "linked list": The "linked list" should use the same TreeNode class where the right child pointer points to the nex…
原文链接: https://leetcode-cn.com/problems/copy-list-with-random-pointer 英文原文A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the li…
原文链接: https://leetcode-cn.com/problems/word-break 英文原文Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary …
原文链接: https://leetcode-cn.com/problems/linked-list-cycle-ii 英文原文Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return null. There is a cycle in a linked list if there is some node in the list that can b…
原文链接: https://leetcode-cn.com/problems/reorder-list 英文原文You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln &r…
原文链接: https://leetcode-cn.com/problems/lru-cache 英文原文Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the LRUCache class: LRUCache(int capacity) Initialize the LRU cache with positive size capacity.…
原文链接: https://leetcode-cn.com/problems/insertion-sort-list 英文原文Given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head. The steps of the insertion sort algorithm: Insertion sort iterates, consumin…
原文链接: 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/reverse-words-in-a-string 英文原文Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a st…
原文链接: 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-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…
原文链接: https://leetcode-cn.com/problems/compare-version-numbers 英文原文Given two version numbers, version1 and version2, compare them. Version numbers consist of one or more revisions joined by a dot '.'. Each revision consists of digits and may contain …
原文链接: https://leetcode-cn.com/problems/fraction-to-recurring-decimal 英文原文Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating par…
原文链接: https://leetcode-cn.com/problems/factorial-trailing-zeroes 英文原文Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1. Example 1: Input: n = 3 Output: 0 Explanation: 3! = 6, no tra…
原文链接: https://leetcode-cn.com/problems/binary-search-tree-iterator 英文原文Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST): BSTIterator(TreeNode root) Initializes an object of the BSTI…
原文链接: https://leetcode-cn.com/problems/second-highest-salary 英文原文Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Ea…
原文链接: https://leetcode-cn.com/problems/nth-highest-salary 英文原文Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each …
原文链接: https://leetcode-cn.com/problems/rank-scores 英文原文Table: Scores +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | score | decimal | +-------------+---------+ id is the primary key for this table. Each row …
原文链接: https://leetcode-cn.com/problems/consecutive-numbers 英文原文Table: Logs +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id is the primary key for this table. Write…
原文链接: https://leetcode-cn.com/problems/largest-number 英文原文Given a list of non-negative integers nums, arrange them such that they form the largest number. Note: The result may be very large, so you need to return a string instead of an integer. Examp…