[LinkedIn]Intersection of two sorted array
来源:互联网 发布:美图秀秀mac官方 编辑:程序博客网 时间:2024/06/11 02:27
print intersection of two sorted array
思路from g4g:
1) Use two index variables i and j, initial values i = 0, j = 0
2) If arr1[i] is smaller than arr2[j] then increment i.
3) If arr1[i] is greater than arr2[j] then increment j.
4) If both are same then print any of them and increment both i and j.
void intersection(int[] a, int[] b) { if(a.length == 0 || b.length == 0) { return 0; } int i = 0, j = 0; while(i <= a.length && j <= b.length) { if(a[i] < b[j]) { i++; } else if(a[i] > b[j]) { j++; } else { System.out.println(a[i]); } }}
0 0
- [LinkedIn]Intersection of two sorted array
- Intersection of two sorted arrays
- find intersection of two sorted arrays
- Median of Two Sorted Array
- Median of two sorted array
- median of two sorted array
- median of two sorted array
- Median of two sorted array
- Leetcode-349-Intersection of Two Array
- LeetCode 349. Intersection of Two Array
- LeetCode 350. Intersection of Two Array
- LeetCode2: Median of Two sorted array.
- LeetCode 4: Median Of Two Sorted Array
- Leetcode - Median of Two Sorted Array
- 133_leetcode_Median of Two Sorted Array
- Median of Two Sorted Array---LeetCode
- [leetcode] #4 Median of Two Sorted Array
- LeetCode:Median of two sorted array
- Sudoku Solver
- [LinkedIn]Merge Sorted Iterator (using comparator)
- 跟我一步一步开发自己的Openfire插件
- LeetCode - Max Points on a Line
- 黑马程序员——Objective-C学习笔记(三):组合
- [LinkedIn]Intersection of two sorted array
- MATLAB indexing question
- 浅解闭包概念
- 我的第一个C语言程序
- Xsolla和亚马逊支付合作,提供游戏内计费方案
- [LinkedIn]find balance (equilibrium) point (index) in an array (unsorted)
- Valid Sudoku
- Remove duplicates from sorted array
- Remove duplicates from sorted array II