로딩
요청 처리 중입니다...

JAVA_LeetCode 264_Ugly Number II

 JAVA_LeetCode 264_Ugly Number II

JAVA_LeetCode 264_Ugly Number II 풀이 class Solution { public int nthUglyNumber(int n) { // 2, 3, 5를 체크하면서 배수와 일치 시 값 초기화한다. // 중복없이 작은 수부터 차례대로 2, 3, 5의 배수를 생성해나가는 구조 int[] ugly = new int[n]; ugly[0] = 1; int i2 = 0, i3 = 0, i5 = 0; int next2 = 2, next3 = 3, next5 = 5; for(int i = 1; i < n; i++){ int nextUgly = Math.min(next2, Math.min(next3, next5)); ugly[i] = nextUgly; if(nextUgly == next2) next2 = ugly[++i2] * 2; if(nextUgly == next3) next3 = ugly[++i3] * 3; if(nextUgly == next5) next5 = ugly[...