代码拉取完成,页面将自动刷新
/*
* @lc app=leetcode.cn id=264 lang=java
*
* [264] 丑数 II
*/
// @lc code=start
class NthUglyNumber {
public int nthUglyNumber(int n) {
int[] dp = new int[n];
dp[0] = 1;
int p2 = 0, p3 = 0, p5 = 0;
for (int i = 1; i < n; i++) {
int res = Math.min(Math.min(dp[p2] * 2, dp[p3] * 3), dp[p5] * 5);
dp[i] = res;
if (res == dp[p2] * 2) {
p2++;
}
if (res == dp[p3] * 3) {
p3++;
}
if (res == dp[p5] * 5) {
p5++;
}
}
return dp[n - 1];
}
}
// @lc code=end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。