LIS 틀린 예제좀 찾아주세요ㅠ

  • hjae
    hjae

    나머진 전부 입력, 출력 부분이고요
    findMax 함수 부분이 직접적인 알고리즘 구현 부분입니다.
    오답이 뜨는데 오답인 예를 아무리 생각해도 못찾겠습니다..

    혹시 만약에 순증가하는 부분이 없으면 길이 0으로 출력해야하는 거 맞죠???

    import java.util.Scanner;

    public class Main {

    public static void main(String [] args) {
        int C, N;
        int nums[], maxs;
    
        Scanner s = new Scanner(System.in);
        C = s.nextInt(); //tests count
    
        for(int i = 0; i < C; i++) {
            N = s.nextInt();
            nums = new int [N];
            for(int j = 0; j < N; j++) {
                nums[j] = s.nextInt();
            }
            maxs = findMax(nums);
            System.out.println(maxs + "");
        }
    }
    
    public static int findMax(int [] getNums) {
        int maxlength = 0, count = 1, flag = 0;
    
        for(int i = 1; i < getNums.length; i++) {
            if(getNums[i-1] < getNums[i]) {
                count++;
                flag = 1;
            }
            else {
                if(maxlength < count && flag == 1)
                    maxlength = count;
                count = 1;
            }
        }
    
        if(maxlength < count && flag == 1)
            maxlength = count;
    
        return maxlength;
    }

    }


    7년 전
1개의 댓글이 있습니다.
  • wee
    wee

    1 10 2 3


    7년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.