描述
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?
For example,
Given n = 3, there are a total of 5 unique BST’s.
1 | 1 3 3 2 1 |
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?
For example,
Given n = 3, there are a total of 5 unique BST’s.
1 | 1 3 3 2 1 |
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.
1 | +----+-------+--------+--------------+ |
The Department table holds all departments of the company.
1 | +----+----------+ |
Write a SQL query to find employees who have the highest salary in each of the departments. For the above tables, Max has the highest salary in the IT department and Henry has the highest salary in the Sales department.
1 | +------------+----------+--------+ |
TODO
输入一个整型数组,数组中的一个或连续多个整数组成一个子数组。求所有子数组的和的最大值。
要求时间复杂度为O(n)。
示例1:
1 | 输入: nums = [-2,1,-3,4,-1,2,1,-5,4] |
提示:
注意:本题与主站 53 题相同:https://leetcode-cn.com/problems/maximum-subarray/
Write a SQL query to get the second highest salary from the Employee
table.
1 | +----+--------+ |
For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.
Table: Person
1 | +-------------+---------+ |
Table: Address
1 | +-------------+---------+ |
Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
1 | FirstName, LastName, City, State |
Write a SQL query to find all numbers that appear at least three times consecutively.
1 | +----+-----+ |
For example, given the above Logs table, 1 is the only number that appears consecutively for at least three times.
Suppose that a website contains two tables, the Customers
table and the Orders
table. Write a SQL query to find all customers who never order anything.
Table: Customers
.
1 | +----+-------+ |
Table: Orders.
1 | +----+------------+ |
Using the above tables as example, return the following:
1 | +-----------+ |
Write a SQL query to find all duplicate emails in a table named Person
.
1 | +----+---------+ |
For example, your query should return the following for the above table:
1 | +---------+ |