首页 > 其他 > 详细

【leetcode】264. 丑数 II

时间:2021-01-07 21:03:31      阅读:36      评论:0      收藏:0      [点我收藏+]

 

#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];
}

 

【leetcode】264. 丑数 II

原文:https://www.cnblogs.com/ganxiang/p/14248159.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!