diff --git a/notes/49. 丑数.md b/notes/49. 丑数.md index f92d4d12..f2aa4566 100644 --- a/notes/49. 丑数.md +++ b/notes/49. 丑数.md @@ -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]; } ```