349. Intersection of Two Arrays#2(Done)
来源:互联网 发布:karunesh 知乎 编辑:程序博客网 时间:2024/06/04 23:34
Solution
public class Solution { public int[] intersection(int[] nums1, int[] nums2) { Arrays.sort(nums1); Arrays.sort(nums2); int[] store = new int[nums1.length]; int i = 0; int j = 0; int count = 0; while (i < nums1.length && j < nums2.length) { if (nums1[i] < nums2[j]) { i++; } else if (nums1[i] > nums2[j]) { j++; } else { if (count == 0 || store[count - 1] != nums1[i]) { store[count++] = nums1[i]; } i++; j++; } } int[] result = new int[count]; for (int k = 0; k < count; k++) { result[k] = store[k]; } return result; }}
Problem#1
不熟悉hashTable
0 0
- 349. Intersection of Two Arrays#2(Done)
- 350. Intersection of Two Arrays II#2(Done)
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays[][
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- SSL 2521 数数
- 关于泛型程序设计和c++标准模板库
- JavaSE学习(10) 集合框架
- 116. Populating Next Right Pointers in Each Node
- Leetcode | Basic Calculator
- 349. Intersection of Two Arrays#2(Done)
- java学习入门
- 【PHP】10个值得深思的PHP面试问题
- Mac VMWare Fusion安装ghost win7注意事项
- Java程序员应当知道的10个面向对象设计原则
- Windows程序设计(1):Hello,world!
- 文章标题
- 郝斌的C语言基础 155 如何取出结构体中的每一个成员
- 实现客户信息显示和添加