public static void LISbetter (int num[]) {//use additional array to store the end of
        //the sequence of current length. Use sequential search to find the position
        //to insert.
        int temp[] = new int [num.length];
        int maxlen = 1;
        temp[0] = num[0];
        for (int i = 1; i < num.length; ++i) {//i is index of num
            int j = 0;
            while (j < maxlen && num[i] > temp[j]) {//j is index of temp
                ++j;
            }
            if (j >= maxlen) maxlen++;
            temp[j] = num[i];
        }
        System.out.println(maxlen);
    }