스터디 문제2번 Heap 정답률 38.9%
https://blog.naver.com/zzang9ha/221771852840
Do it! 자료구조와 함께 배우는 알고리즘 입문 - 자바 6. 정렬 : 힙 정렬(Heap Sort)
*** 위 교재로 공부한 내용입니다. ***힙이란? 힙 정렬(Heap Sort)는 힙을 사용하여 정렬하는 알고리즘...
blog.naver.com
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
JeasonWong/LeetCode
没事刷刷题也是好的. Contribute to JeasonWong/LeetCode development by creating an account on GitHub.
github.com
'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 |
댓글