import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
int []arr=new int[n+1];
for(int i=1;i<=n;i++){
arr[i]=Integer.parseInt(st.nextToken());
}
ArrayList<Integer>list=new ArrayList<>();
list.add(arr[1]);
for(int i=2;i<=n;i++){
int num=arr[i];
if(num>list.get(list.size()-1)){
list.add(num);
}
else{
int left=0;
int right=list.size()-1;
while(left<right){
int mid=(left+right)/2;
if(num<=list.get(mid)){
right=mid;
}
else{
left=mid+1;
}
}
list.set(left,num);
}
}
System.out.println(list.size());
}
}
가장 작은 끝 값은 이분 탐색을 통햇 찾아서 값을 바꾸어 주자.
'프로그래머스 백준 문제' 카테고리의 다른 글
| 10026번 적록색약 (3) | 2025.07.17 |
|---|---|
| 가장 긴 공통인 수열(문장) (0) | 2025.07.16 |
| 3986 좋은 단어 (0) | 2025.07.14 |
| 자바 CompareTo 와 Compare 비교 및 차이(1181번,11650번) (0) | 2025.06.21 |
| 9935번 문자열 폭발 (2) | 2025.06.19 |