Given the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).
Example 1:
1 | Input: root = [3,9,20,null,null,15,7] |
Example 2:
1 | Input: root = [1] |
Example 3:
1 | Input: root = [] |
Given the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).
Example 1:
1 | Input: root = [3,9,20,null,null,15,7] |
Example 2:
1 | Input: root = [1] |
Example 3:
1 | Input: root = [] |
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
Example 1:
1 | Input: p = [1,2,3], q = [1,2,3] |
Example 2:
1 | Input: p = [1,2], q = [1,null,2] |
Example 3:
1 | Input: p = [1,2,1], q = [1,1,2] |
Given the root of a binary tree, determine if it is a valid binary search tree (BST).
A valid BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
Both the left and right subtrees must also be binary search trees.
Example 1:
1 | Input: root = [2,1,3] |
Example 2:
1 | Input: root = [5,1,4,null,null,3,6] |
A message containing letters from A-Z can be encoded into numbers using the following mapping:
1 | 'A' -> "1" |
To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, “11106” can be mapped into:
1 | "AAJF" with the grouping (1 1 10 6) |
Note that the grouping (1 11 06) is invalid because “06” cannot be mapped into ‘F’ since “6” is different from “06”.
Given a string s containing only digits, return the number of ways to decode it.
The answer is guaranteed to fit in a 32-bit integer.
Example 1:
1 | Input: s = "12" |
Example 2:
1 | Input: s = "226" |
Example 3:
1 | Input: s = "0" |
Example 4:
1 | Input: s = "06" |
Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place.
Example 1:
1 | Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] |
Example 2:
1 | Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] |