349. Intersection of Two Arrays#2(Done)
2016-12-09 21:16
701 查看
Solution
Problem#1
不熟悉hashTable
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
相关文章推荐
- hdu 1039 Easier Done Than Said?
- ios开发之tableview的编辑模式下的Edit Done Delete按钮文本
- Part2:Unity学习笔记十四 - Space Shooter(从视频最后一课向Done_Main.unity场景修改的过程)
- hdu 1039 Easier Done Than Said?
- $.when().done().then()的用法
- Shell中while循环的done 后接一个重定向<
- 36. Valid Sudoku徒手尝试#3(Done)
- 125. Valid Palindrome#2(Done)
- 448. Find All Numbers Disappeared in an Array#2(Done)
- 268. Missing Number#1(Done)
- Linux内核启动卡在Uncompressing Linux... done, booting the kernel[转载]
- 解决 UnityEditor.AsyncHTTPClient:Done
- 一分钟了解“do and has done”
- HDU 1039 Easier Done Than Said? (字符串)
- HDU 1039 Easier Done Than Said?(正则表达式)
- python threading queue模块中join setDaemon及task_done的使用方法及示例
- 一年一度与“首尔” 【DONE!】
- What I've done
- The type of publishing done for this blog.
- 内核移植错误:Uncompressing Linux............................... done, booting the kernel