PikachuBLOG


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

117. Populating Next Right Pointers in Each Node II

发表于 2017-08-18 | 分类于 LeetCode | 阅读次数
字数统计 389 | 阅读时长 2

117. Populating Next Right Pointers in Each Node II

Follow up for problem “Populating Next Right Pointers in Each Node”.
What if the given tree could be any binary tree? Would your previous solution still work?

Note:
  You may only use constant extra space.

1
2
3
4
5
6
7
8
9
10
11
12
13
For example,
Given the following binary tree,
1
/ \
2 3
/ \ \
4 5 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ \
4-> 5 -> 7 -> NULL
阅读全文 »

116. Populating Next Right Pointers in Each Node

发表于 2017-08-17 | 分类于 LeetCode | 阅读次数
字数统计 554 | 阅读时长 2

116. Populating Next Right Pointers in Each Node

Given a binary tree

​ struct TreeLinkNode {
​ TreeLinkNode left;
​ TreeLinkNode
right;
​ TreeLinkNode *next;
​ }
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.

Note:

You may only use constant extra space.
​ You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).

1
2
3
4
5
6
7
8
9
10
11
12
13
For example,
Given the following perfect binary tree,
1
/ \
2 3
/ \ / \
4 5 6 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ / \
4->5->6->7 -> NULL
阅读全文 »

115. Distinct Subsequences

发表于 2017-08-16 | 分类于 LeetCode | 阅读次数
字数统计 687 | 阅读时长 3

115. Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S.

A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ACE” is a subsequence of “ABCDE” while “AEC” is not).

Here is an example:
S = “rabbbit”, T = “rabbit”

Return 3.

阅读全文 »

114. Flatten Binary Tree to Linked List

发表于 2017-08-16 | 分类于 LeetCode | 阅读次数
字数统计 720 | 阅读时长 3

114. Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
For example,
Given
1
/ \
2 5
/ \ \
3 4 6

The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
阅读全文 »

113. Path Sum II

发表于 2017-08-16 | 分类于 LeetCode | 阅读次数
字数统计 705 | 阅读时长 3

113. Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
For example:
Given the below binary tree and sum = 22,
5
/ \
4 8
/ / \
11 13 4
/ \ / \
7 2 5 1
return
[
[5,4,11,2],
[5,8,4,5]
]
阅读全文 »

112. Path Sum

发表于 2017-08-15 | 分类于 LeetCode | 阅读次数
字数统计 860 | 阅读时长 4

112. Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

1
2
3
4
5
6
7
8
9
10
For example:
Given the below binary tree and sum = 22,
5
/ \
4 8
/ / \
11 13 4
/ \ \
7 2 1
return true, as there exist a root-to-leaf path 5->4->11->2 which sum is 22.
阅读全文 »

111. Minimum Depth of Binary Tree

发表于 2017-08-15 | 分类于 LeetCode | 阅读次数
字数统计 249 | 阅读时长 1

111. Minimum Depth of Binary Tree

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.

阅读全文 »

110. Balanced Binary Tree

发表于 2017-08-15 | 分类于 LeetCode | 阅读次数
字数统计 616 | 阅读时长 3

110. Balanced Binary Tree

Given a binary tree, determine if it is height - balanced.

For this problem, a height - balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

阅读全文 »

109. Convert Sorted List to Binary Search Tree

发表于 2017-08-15 | 分类于 LeetCode | 阅读次数
字数统计 581 | 阅读时长 3

109. Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

题意:

  给定一个单项升序链表,把其转换成二叉搜索树。

阅读全文 »

108. Convert Sorted Array to Binary Search Tree

发表于 2017-08-14 | 分类于 LeetCode | 阅读次数
字数统计 201 | 阅读时长 1

108. Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

阅读全文 »
1…678…17
CodePikachu

CodePikachu

技术随笔

168 日志
5 分类
7 标签
RSS
GitHub Twitter 微博 知乎
0%
© 2015 - 2020 CodePikachu
博客全站共123.3k字
本站访客数:
由 Hexo 强力驱动
主题 - NexT.Pisces