Update 49. 丑数.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:06 +08:00
parent fbd5a0d2c4
commit 52d0dd2e3c
+7 -7
View File
@@ -1,6 +1,6 @@
# 49. 丑数
[NowCoder](https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b?tpId=13&tqId=11186&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/chou-shu-lcof/)
## 题目描述
@@ -9,13 +9,13 @@
## 解题思路
```java
public int GetUglyNumber_Solution(int N) {
if (N <= 6)
return N;
public int nthUglyNumber(int n) {
if (n <= 6)
return n;
int i2 = 0, i3 = 0, i5 = 0;
int[] dp = new int[N];
int[] dp = new int[n];
dp[0] = 1;
for (int i = 1; i < N; i++) {
for (int i = 1; i < n; i++) {
int next2 = dp[i2] * 2, next3 = dp[i3] * 3, next5 = dp[i5] * 5;
dp[i] = Math.min(next2, Math.min(next3, next5));
if (dp[i] == next2)
@@ -25,6 +25,6 @@ public int GetUglyNumber_Solution(int N) {
if (dp[i] == next5)
i5++;
}
return dp[N - 1];
return dp[n - 1];
}
```