技术自留地


  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

669. Trim a Binary Search Tree

发表于 2017-10-16 | 分类于 LeetCode

Given a binary search tree and the lowest and highest boundaries as L and R, 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

发表于 2017-10-16 | 分类于 LeetCode

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:

  1. The range of node’s value is in the range of 32-bit signed integer.
阅读全文 »

463. Island Perimeter

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:
0 ≤ x, y < 2^31.

阅读全文 »
1…56
chaopengz

chaopengz

北航|北大|码农|图形学

56 日志
12 分类
15 标签
© 2021 chaopengz
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.3