国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

java - 兩組數(shù)組,長度不一樣,如果其中一個數(shù)組的值在另一個中不存在,則不符合要求.怎么算?
迷茫
迷茫 2017-04-17 16:18:33
0
4
587

一定要是一組數(shù)組完全包含另一組數(shù)組里的全部值,長度可以不同.一個值不同則不符合要求.

迷茫
迷茫

業(yè)精于勤,荒于嬉;行成于思,毀于隨。

reply all(4)
黃舟

SetA and SetB, assuming that the length of SetA is less than or equal to SetB, then SetA - SetB code> should be an empty set to meet your requirements. Otherwise, even if it is not SetASetB, 假設(shè)SetA的長度小于等于SetB, 那么SetA - SetB就應(yīng)該是空集, 才能滿足你的要求. 否則就算不是

C++標(biāo)準(zhǔn)庫有一個庫函數(shù)std::set_difference

The C++ standard library has a library function std::set_difference that can be used to calculate the difference of sets.

PS: The two sets must be sorted??
Peter_Zhu

There is a method in Java called list.containsAll()

    public static void main(String args[]){
        String[] a = {"01", "02", "03", "04","05"};
        String[] b = {"01", "05", "03"};
        System.out.println("isContains = " + isContains(a, b));
    }

    private static boolean isContains(String[] a,String[] b) {
        List<String> listA = Arrays.asList(a);
        List<String> listB = Arrays.asList(b);
        return listA.containsAll(listB);
    }
巴扎黑

implementation of javascript

var p1=[77,9999,1];
var p2=[1,2,0,9999,4,65,77];

function isSubArray(p1,p2){
    var i= 0,j= 0,resultArray=[];
    p1.sort();
    p2.sort();
    if(p1[0]>p2[p2.length-1]||p1[p1.length-1]<p2[0]||p1.length>p2.length){
        return false;
    }
    while(i<p1.length){
     while(j<p2.length){
         if(p1[i]>p2[j]){
             j++;
         }else if(p1[i]<p2[j]){
            i++;
            break;
         }else{
             resultArray.push(p1[i]);
             i++;
             j++;
         }
     }

     if(j==p2.length){
         break;
     }
    }
    return resultArray.length===p1.length;
}
!isSubArray(p1,p2)?console.log('p1 isn\'t subset of p2'):console.log('p1 is subset of p2');
大家講道理

Idea 1

Find the longest array first, then loop the short array and determine whether the element is in the long array

public class Main {

    public static void main(String[] args) throws CloneNotSupportedException {
        String[] strArr1={"ee","aa","bb","cc"};
        String[] strArr2={"aa","bb","cc","dd","44"};
        System.out.println(Main.subContain(strArr1,strArr2));
    }

    public static boolean subContain(String[] strArr1, String[] strArr2) {
        if (null == strArr1 || null == strArr2) {
            return false;
        }

        boolean flag = true;

        if (strArr2.length > strArr1.length) {
            String[] temp;
            temp = strArr1;
            strArr1 = strArr2;
            strArr2 = temp;
        }

        for (String str : strArr2) {
            if (!Arrays.asList(strArr1).contains(str)) {
                flag = false;
                break;
            }
        }

        return flag;
    }
}

Idea 2

To determine whether the intersection length of two arrays is equal to the minimum array length, a third-party jar package is used

public class Main {

    public static void main(String[] args) throws CloneNotSupportedException {
        String[] strArr1 = {"aa", "bb", "cc"};
        String[] strArr2 = {"aa", "bb", "cc", "dd", "44"};
        System.out.println(Main.subContain(strArr1, strArr2));
    }

    public static boolean subContain(String[] strArr1, String[] strArr2) {
        if (null == strArr1 || null == strArr2) {
            return false;
        }

        Collection collection = org.apache.commons.collections.CollectionUtils.intersection(Arrays.asList(strArr1), Arrays.asList(strArr2));
        return collection.size() == Math.min(strArr1.length, strArr2.length);
    }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template