codewars050: 丟失的數組的長度

Instructions

Length of missing arrayjava

Solution:

//--https://www.codewars.com/kata/57b6f5aadb5b3d0ae3000611/train/java
import java.util.Arrays;
public class Kata{
    public static int getLengthOfMissingArray(Object[][] arrayOfArrays){
        if(arrayOfArrays == null || arrayOfArrays.length == 0){
            return 0;
        }    
        int[] arr = new int[arrayOfArrays.length];
        for(int i = 0; i < arr.length; i++){
            if(arrayOfArrays[i] == null || arrayOfArrays[i].length == 0){
                return 0;
            }    
            arr[i] = arrayOfArrays[i].length;
        }    
        Arrays.sort(arr);
        int rslt = arr[0];
        for(arr[i] != ++rslt){
            return rslt;
        }    
    }    
    return 0;
  }  
}

Example Tests:

To be pasted.
相關文章
相關標籤/搜索