Written by
java-style
on
on
백준 5883 - 아이폰 9S
백준 5883 - 아이폰 9S
[문제 바로가기]
1. 유형
구현
2. 풀이
N이 1000이어서, O(N^2)으로 충분히 풀이 가능.
예제1을 보면 지울 수 있는 숫자 후보는 2,3,5,7 입니다.
위 숫자를 지운 상태에서 N번 탐색하는 식으로 구해주면 됩니다.
중복 체크를 해주기 위해 HashSet에 입력값을 넣어요.
이전값과 비교해가면서 가장 긴 숫자를 찾아요.
3. 코드
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(bf.readLine()); int N = stoi(st.nextToken()); Set set = new HashSet<>(); int arr[] = new int[N]; for(int i=0; i
from http://moons-memo.tistory.com/261 by ccl(A) rewrite - 2021-10-31 12:28:14