codewars058: Which are in?

Instructions:

Linkjava

Solution:

import java.util.*;
public class WhichAreIn{
    public static String[] inArray(String[] array1, String[] array2){
        List<String> list = new ArrayList<String>();
        for(int i = 0; i < array1.length; i++){
            for(int j = 0; j < array2.length; j++){
                if(!list.contains(array1[i])){
                    list.add(array1[i]);
                    break;
                }    
            }    
        }    
        String[] rslt = list.toArray(new String[0]);
        Arrays.sort(rslt);
        return rslt;
    }    
}

Example Tests:

//https://www.codewars.com/kata/550554fd08b86f84fe000a58/train/java
相關文章
相關標籤/搜索