Description
https://leetcode.com/problems/palindrome-permutation-ii/
Solution
1 | class Solution { |
Why don't you come to your senses?
https://leetcode.com/problems/palindrome-permutation-ii/
1 | class Solution { |
1 | class Solution { |
Unfortunately, this implementation can result in the memory excess in the last test case. So why don’t be naive, or let’s say, back to the origin.
1 | class Solution { |
https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers as synonymous to the previous and next pointers in a doubly-linked list.
Let’s take the following BST as an example, it may help you understand the problem better:
We want to transform this BST into a circular doubly linked list. Each node in a doubly linked list has a predecessor and successor. For a circular doubly linked list, the predecessor of the first element is the last element, and the successor of the last element is the first element.
The figure below shows the circular doubly linked list for the BST above. The “head” symbol means the node it points to is the smallest element of the linked list.
1 | /* |
https://leetcode.com/problems/maximum-binary-tree/description/
1 | /** |
1 | /** |
https://leetcode.com/problems/remove-k-digits/
1 | class Solution { |
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open (
and closing parentheses )
, the plus +
or minus sign -
, non-negativeintegers and empty spaces .
The expression string contains only non-negative integers, +
, -
, *
, /
operators , open (
and closing parentheses )
and empty spaces . The integer division should truncate toward zero.
You may assume that the given expression is always valid. All intermediate results will be in the range of [-2147483648, 2147483647]
.
1 | enum Type { |
https://leetcode.com/problems/validate-binary-search-tree/
1 | /** |
https://leetcode.com/problems/graph-valid-tree/
Given n
nodes labeled from 0
to n-1
and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree.
Example 1:
1 | Input: n = 5, and edges = [[0,1], [0,2], [0,3], [1,4]] |
Example 2:
1 | Input: n = 5, and edges = [[0,1], [1,2], [2,3], [1,3], [1,4]] |
Note: you can assume that no duplicate edges will appear in edges
. Since all edges are undirected, [0,1]
is the same as [1,0]
and thus will not appear together in edges
1 | class Solution { |
1 | class Solution { |