描述
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
In a string S
of lowercase letters, these letters form consecutive groups of the same character.
For example, a string like S = "abbxxxxzyy"
has the groups "a"
, "bb"
, "xxxx"
, "z"
and "yy"
.
Call a group large if it has 3 or more characters. We would like the starting and ending positions of every large group.
The final answer should be in lexicographic order.
Example 1:
1 | Input: "abbxxxxzzy" |
Example 2:
1 | Input: "abc" |
Example 3:
1 | Input: "abcdddeeeeaabbbcd" |
Note: 1 <= S.length <= 1000
There are N
rooms and you start in room 0
. Each room has a distinct number in 0, 1, 2, ..., N-1
, and each room may have some keys to access the next room.
Formally, each room i
has a list of keys rooms[i]
, and each key rooms[i][j]
is an integer in [0, 1, ..., N-1]
where N = rooms.length
. A key rooms[i][j] = v
opens the room with number v
.
Initially, all the rooms start locked (except for room 0
).
You can walk back and forth between rooms freely.
Return true
if and only if you can enter every room.
Example 1:
1 | Input: [[1],[2],[3],[]] |
Example 2:
1 | Input: [[1,3],[3,0,1],[2],[0]] |
Note:
1 <= rooms.length <= 1000
0 <= rooms[i].length <= 1000
3000
.A rectangle is represented as a list [x1, y1, x2, y2]
, where (x1, y1)
are the coordinates of its bottom-left corner, and (x2, y2)
are the coordinates of its top-right corner.
Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles that only touch at the corner or edges do not overlap.
Given two (axis-aligned) rectangles, return whether they overlap.
Example 1:
1 | Input: rec1 = [0,0,2,2], rec2 = [1,1,3,3] |
Example 2:
1 | Input: rec1 = [0,0,1,1], rec2 = [1,0,2,1] |
Notes:
rec1
and rec2
are lists of 4 integers.-10^9
and 10^9
.Let’s call an array A
a mountain if the following properties hold:
A.length >= 3
0 < i < A.length - 1
such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
Given an array that is definitely a mountain, return any i
such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1]
.
Example 1:
1 | Input: [0,1,0] |
Example 2:
1 | Input: [0,2,1,0] |
Note:
3 <= A.length <= 10000
0 <= A[i] <= 10^6
Given two strings S
and T
, return if they are equal when both are typed into empty text editors. #
means a backspace character.
Example 1:
1 | Input: S = "ab#c", T = "ad#c" |
Example 2:
1 | Input: S = "ab##", T = "c#d#" |
Example 3:
1 | Input: S = "a##c", T = "#a#c" |
Example 4:
1 | Input: S = "a#c", T = "b" |
Note:
1 <= S.length <= 200
1 <= T.length <= 200
S
and T
only contain lowercase letters and '#'
characters.Follow up:
O(N)
time and O(1)
space?At a lemonade stand, each lemonade costs $5
.
Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills
).
Each customer will only buy one lemonade and pay with either a $5
, $10
, or $20
bill. You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.
Note that you don’t have any change in hand at first.
Return true
if and only if you can provide every customer with correct change.
Example 1:
1 | Input: [5,5,5,10,20] |
Example 2:
1 | Input: [5,5,10] |
Example 3:
1 | Input: [10,10] |
Example 4:
1 | Input: [5,5,10,10,20] |
Note:
0 <= bills.length <= 10000
bills[i]
will be either 5
, 10
, or 20
.Given a balanced parentheses string S
, compute the score of the string based on the following rule:
()
has score 1AB
has score A + B
, where A and B are balanced parentheses strings.(A)
has score 2 * A
, where A is a balanced parentheses string.Example 1:
1 | Input: "()" |
Example 2:
1 | Input: "(())" |
Example 3:
1 | Input: "()()" |
Example 4:
1 | Input: "(()(()))" |
TOREVIEW
Given the root
of a binary tree, the value of a target node target
, and an integer k
, return an array of the values of all nodes that have a distance k
from the target node.
You can return the answer in any order.
Example 1:
1 | Input: root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2 |
Example 2:
1 | Input: root = [1], target = 1, k = 3 |
Constraints:
[1, 500]
.0 <= Node.val <= 500
Node.val
are unique.target
is the value of one of the nodes in the tree.0 <= k <= 1000
Given a matrix A
, return the transpose of A
.
The transpose of a matrix is the matrix flipped over it’s main diagonal, switching the row and column indices of the matrix.
Example 1:
1 | Input: [[1,2,3],[4,5,6],[7,8,9]] |
Example 2:
1 | Input: [[1,2,3],[4,5,6]] |
Note:
1 <= A.length <= 1000
1 <= A[0].length <= 1000