Given a binary search tree and the lowest and highest boundaries as
L
andR
, trim the tree so that all its elements lies in[L, R]
(R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.
637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.
Example 1:
1
2
3
4
5
6
7
8
9
10 > > Input:
> > 3
> > / \
> > 9 20
> > / \
> > 15 7
> > Output: [3, 14.5, 11]
> > Explanation:
> > The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11].
>Note:
- The range of node’s value is in the range of 32-bit signed integer.
463. Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes” (water inside that isn’t connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.
Example:
1
2
3
4
5
6
7
8
9 > >[[0,1,0,0],
> > [1,1,1,0],
> > [0,1,0,0],
> > [1,1,0,0]]
> >
> >Answer: 16
> >Explanation: The perimeter is the 16 yellow stripes in the image below:
>
>
557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
1
2
3
4
5 > > >Input: "Let's take LeetCode contest"
> > >Output: "s'teL ekat edoCteeL tsetnoc"
> > >
> > >
> >
>
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
617. Merge Two Binary Trees
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.
You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.
461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers
x
andy
, calculate the Hamming distance.Note:
0 ≤x
,y
< 2^31.