code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

263 Ugly Number

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

const uglyNumber = n => {
  if (n <= 0) {
    return false
  }
  const nums = [2, 3, 5]
  for (let i = 0; i < nums.length; i++) {
    while (n % nums[i] == 0) {
      n = Math.floor(n / nums[i])
    }
  }
  return n == 1
}

console.log(uglyNumber(6))

Created 2022-03-20T09:29:13+00:00 · Edit