Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
Example:
1 | Input: "aab" |
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
Example:
1 | Input: "aab" |
Determine if a 9 x 9
Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
1-9
without repetition.1-9
without repetition.3 x 3
sub-boxes of the grid must contain the digits 1-9
without repetition.Note:
Example 1:
1 | Input: board = |
Example 2:
1 | Input: board = |
Constraints:
board.length == 9
board[i].length == 9
board[i][j]
is a digit or '.'
.Given a string s
containing only digits, return all possible valid IP addresses that can be obtained from s
. You can return them in any order.
A valid IP address consists of exactly four integers, each integer is between 0
and 255
, separated by single dots and cannot have leading zeros. For example, “0.1.2.201” and “192.168.1.1” are valid IP addresses and “0.011.255.245”, “192.168.1.312” and “192.168@1.1“ are invalid IP addresses.
Example 1:
1 | Input: s = "25525511135" |
Example 2:
1 | Input: s = "0000" |
Example 3:
1 | Input: s = "1111" |
Example 4:
1 | Input: s = "010010" |
Example 5:
1 | Input: s = "101023" |
Constraints:
0 <= s.length <= 3000
s
consists of digits only.Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path.
In a UNIX-style file system, a period .
refers to the current directory. Furthermore, a double period ..
moves the directory up a level.
Note that the returned canonical path must always begin with a slash /
, and there must be only a single slash /
between two directory names. The last directory name (if it exists) must not end with a trailing /
. Also, the canonical path must be the shortest string representing the absolute path.
Example 1:
1 | Input: "/home/" |
Example 2:
1 | Input: "/../" |
Example 3:
1 | Input: "/home//foo/" |
Example 4:
1 | Input: "/a/./b/../../c/" |
Example 5:
1 | Input: "/a/../../b/../c//.//" |
Example 6:
1 | Input: "/a//b////c/d//././/.." |
Given a 2D board containing 'X'
and 'O'
(the letter O), capture all regions surrounded by 'X'
.
A region is captured by flipping all 'O'
s into 'X'
s in that surrounded region.
Example:
1 | X X X X |
After running your function, the board should be:
1 | X X X X |
Explanation:
Surrounded regions shouldn’t be on the border, which means that any 'O'
on the border of the board are not flipped to 'X'
. Any 'O'
that is not on the border and it is not connected to an 'O'
on the border will be flipped to 'X'
. Two cells are connected if they are adjacent cells connected horizontally or vertically.
Given a binary tree containing digits from 0-9
only, each root-to-leaf path could represent a number.
An example is the root-to-leaf path 1->2->3
which represents the number 123
.
Find the total sum of all root-to-leaf numbers.
Note: A leaf is a node with no children.
Example:
1 | Input: [1,2,3] |
Example 2:
1 | Input: [4,9,0,5,1] |
Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
Note:
Example 1:
1 | Input: |
Example 2:
1 | Input: |
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
The Linked List is represented in the input/output as a list of n
nodes. Each node is represented as a pair of [val, random_index]
where:
val
: an integer representing Node.val
random_index
: the index of the node (range from 0
to n-1
) where random pointer points to, or null
if it does not point to any node.Example 1:
1 | Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]] |
Example 2:
1 | Input: head = [[1,1],[2,1]] |
Example 3:
1 | Input: head = [[3,null],[3,0],[3,null]] |
Example 4:
1 | Input: head = [] |
Constraints:
-10000 <= Node.val <= 10000
Node.random
is null or pointing to a node in the linked list.Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
Note: A leaf is a node with no children.
Example 1:
1 | Input: root = [3,9,20,null,null,15,7] |
Example 2:
1 | Input: root = [2,null,3,null,4,null,5,null,6] |
Constraints:
[0, 104]
.-1000 <= Node.val <= 1000
Given a binary tree
1 | struct Node { |
Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL
.
Initially, all next pointers are set to NULL
.
Follow up:
Example 1:
1 | Input: root = [1,2,3,4,5,null,7] |
Constraints:
6000
.-100 <= node.val <= 100