[Java / 코딩테스트] 최대 길이 연속수열
·
알고리즘 & 코딩 테스트/Java로 푼 코딩 테스트
1. 생각 중복을 제거해야 하므로 Set을 쓰면 될거같은데 정렬을 해야하나? nums의 길이가 300,000 이므로 시간복잡도를 최대한 적게 써야한다. 정렬 없는 HashSet으로 해결 2. 코드 import java.util.*; class Solution { public int solution(int[] nums){ int answer = 0; HashSet numSet = new HashSet(); for (int num : nums) { numSet.add(num); } for (Integer i : numSet) { if(numSet.contains(i-1)) continue; int cnt = 0; while (numSet.contains(i)) { cnt++; i++; } answer = M..
마볼링
'Set' 태그의 글 목록