스터디 문제2번 Heap 정답률 38.9%
https://blog.naver.com/zzang9ha/221771852840
public class Solution {
public int nthUglyNumber(int n) {
int result = 1;
int array[] = new int[n+1];
int m2 = 0, m3 = 0, m5 = 0;
array[0] = 1;
for(int i=1; i<n; i++){
int a = array[m2]*2;
int b = array[m3]*3;
int c = array[m5]*5;
array[i] = min(a, b, c);
if(array[i] == a) m2++;
if(array[i] == b) m3++;
if(array[i] == c) m5++;
}
return array[n-1];
}
public int min(int i, int j, int k){
return ((i<j?i:j)<k)?(i<j?i:j):k;
}
}
https://github.com/JeasonWong/LeetCode/blob/master/264.%20Ugly%20Number%20II.java
'Leetcode' 카테고리의 다른 글
Leetcode <Sort> 242. Valid Anagram 백준 6996번 애너그램 (0) | 2020.04.05 |
---|---|
Leetcode 328. Odd Even Linked List 52.5% Medium (0) | 2020.04.03 |
Leetcode 621. Task Scheduler 47.7% Medium (0) | 2020.04.03 |
Leetcode 96. Unique Binary Search Trees 50.1% Medium (0) | 2020.04.03 |
Leetcode 144. Binary Tree Preorder Traversal 54.3% Medium (0) | 2020.04.03 |
댓글