lintcode 548 两数组的交2
来源:互联网 发布:akg k309 知乎 编辑:程序博客网 时间:2024/06/05 23:07
public class Solution { /* * @param nums1: an integer array * @param nums2: an integer array * @return: an integer array */ public int[] intersection(int[] nums1, int[] nums2) { // write your code here if(nums1.length == 0 || nums2.length == 0){ return new int[]{}; } Arrays.sort(nums1); Arrays.sort(nums2); int index1 =0; int index2 = 0; List<Integer> list = new ArrayList<Integer>(); List<Integer> list2 = new ArrayList<Integer>(); while(index1<nums1.length && index2<nums2.length){ if(nums1[index1] == nums2[index2]){ list.add(nums1[index1]); index1++; index2++; }else if(nums1[index1] < nums2[index2]){ index1++; }else{ index2++; } } int []res = new int [list.size()]; for (int i = 0; i<list.size();i++){ res[i] = list.get(i); } return res; }};
阅读全文
0 0
- lintcode 548 两数组的交2
- LintCode 548 两数组的交 II
- LintCode:两数组的交
- LintCode:两数组的交
- 两数组的交-LintCode
- lintcode 两数组的交
- LintCode-两数组的交
- Lintcode 两数组的交
- LintCode 两数组的交
- LintCode(两数组的交)
- 两数组的交-LintCode
- lintcode 547两数组的交 lintcode 548两数组的交II
- LintCode(easy)两数组的交
- LintCode:两数组的交 II
- lintcode:两数组的交二
- LintCode 547 两数组的交
- LintCode【两数组的交II】
- 【lintcode笔记】两数组的交
- Linux基础命令与常用目录
- maven 学习
- CSS变量
- 程序员如何高效学习(以 Java 为例)
- android手机屏幕适配解决方案(1)
- lintcode 548 两数组的交2
- Android ARM64 如何指定链接脚本文件.
- 第一次使用Android Studio时你应该知道的一切配置(三):gradle项目构建
- java中mongoDB连接遇到的问题
- TP3.2_1
- Linux的常用命令
- centos7下配置Hadoop全分布式环境
- 如何成为一个数据驱动的公司?
- Appium使用swipe定位滚动列表和滚动屏幕元素