【leetcode】264. 丑数 II
作者:互联网
#define min(a,b) ((a)<(b))?(a):(b) int nthUglyNumber(int n){ int nums[1691] = {0}; nums[0]=1; int ugly, i2 = 0, i3 = 0, i5 = 0; for(int i = 1; i < n; ++i) { ugly = min( min(nums[i2] * 2, nums[i3] * 3), nums[i5] * 5); nums[i] = ugly; if (ugly == nums[i2] * 2) ++i2; if (ugly == nums[i3] * 3) ++i3; if (ugly == nums[i5] * 5) ++i5; } return nums[n-1]; }
标签:丑数,min,II,264,leetcode,define 来源: https://www.cnblogs.com/ganxiang/p/14248159.html