HT349IntersectionOfTwoArray
2016-11-01 05:20
134 查看
Should give three ways, by the tags
First time write binary search, but can be optimized.
Under this situation –>,
–> If we don’t want duplicate element in the result, we can use set to hold the result, rather than checking the last element in the result.
First time write binary search, but can be optimized.
Faults
When comparing sorted array, I only considered the equal condition of two numbers, while the bigger and smaller can be used as the increment condition as well.Under this situation –>,
if (array1[i] < array2[j])or something, the increment must be executed after the assertion that
i < array1.size() and j < array2.size()
–> If we don’t want duplicate element in the result, we can use set to hold the result, rather than checking the last element in the result.
相关文章推荐
- 【特别好】【位运算】maximum-xor-of-two-numbers-in-an-array
- Leetcode-Two Sum II - Input array is sorted
- 421. Maximum XOR of Two Numbers in an Array
- Two Sum II - Input array is sorted
- Leetcode 167 Two Sum II - Input array is sorted
- Data Structure Array: Find the minimum distance between two numbers
- Two Sum II - Input array is sorted
- 算法系列——Two Sum II - Input array is sorted
- 【Leetcode】238-Product of Array Except Self【Java实现】【Medium】【two way traverse】
- Find the kth smallest element in two sorted array
- [leetcode] #4 Median of Two Sorted Array
- LeetCode 4 Median of Two Sorted Array
- LeetCode 421 Maximum XOR of Two Numbers in an Array 解题报告
- 133_leetcode_Median of Two Sorted Array
- compare two array
- leetcode_167 Two Sum II - Input array is sorted
- Two Stacks In One Array
- [leetcode]421. Maximum XOR of Two Numbers in an Array
- 421. Maximum XOR of Two Numbers in an Array详解
- lintcode(608)Two Sum - Input array is sorted