
1. LeetCode 297. Serialize and DeSerialize Binary Tree
题目:Design an algorithm to serialize and deserialize a binary tree.
1 |
You may serialize the following tree: |
2. LeetCode 652. Find Duplicate Subtrees
题目: Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any oneof them.
Two trees are duplicate if they have the same structure with same node values.
//画recursion tree
Example 1:
1 |
1 |
The following are two duplicate subtrees:
1 |
2 |
and
1 |
4 |
Therefore, you need to return above trees’ root in the form of a list.
3. LeetCode 572. Subtree of Another Tree
Example 1:
Given tree s:
1 |
3 |
Given tree t:
1 |
4 |
Return
true
, because t has the same structure and node values with a subtree of s.
Example 2:
Given tree s:
1 |
3 |
Given tree t:
1 |
4 |
Return
false
关于—前缀和
1.前缀和 + hashTable
1. LeetCode 560. Subarray Sum Equals K
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Example 1:
1 |
Input:nums = [1,1,1], k = 2 |
Note:
- The length of the array is in range [1, 20,000].
- The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
2. LeetCode 325. Maximum Size Subarray Sum Equals K
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn’t one, return 0 instead.
Note:
The sum of the entire nums array is guaranteed to fit within the 32-bit signed integer range.
Example 1:
1 |
Input: nums = [1, -1, 5, -2, 3], k = 3 |
Example 2:
1 |
Input: nums = [-2, -1, 2, 1], k = 1 |
Follow Up:
Can you do it in O(n) time?
.




近期评论