263. Ugly Number

Easy

Write a program to check whether a given number is an ugly number.

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.

Example 1:

Input: 6
Output: true
Explanation: 6 = 2 × 3

Example 2:

Input: 8
Output: true
Explanation: 8 = 2 × 2 × 2

Example 3:

Input: 14
Output: false
Explanation: 14 is not ugly since it includes another prime factor 7.

Note:

  1. 1 is typically treated as an ugly number.
  2. Input is within the 32-bit signed integer range: [−231,  231 − 1].
package leetcode.easy;

public class UglyNumber {
public boolean isUgly(int num) {
if (num <= 0) {
return false;
}
while (num % 2 == 0) {
num = num / 2;
}
while (num % 3 == 0) {
num = num / 3;
}
while (num % 5 == 0) {
num = num / 5;
}
return num == 1;
} @org.junit.Test
public void test() {
System.out.println(isUgly(6));
System.out.println(isUgly(8));
System.out.println(isUgly(14));
System.out.println(isUgly(0));
}
}

LeetCode_263. Ugly Number的更多相关文章

  1. [LeetCode] Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  2. [LeetCode] Ugly Number II 丑陋数之二

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  3. [LeetCode] Ugly Number 丑陋数

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  4. 【13_263】Ugly Number

    简单题 Ugly Number My Submissions Question Total Accepted: 32635 Total Submissions: 94009 Difficulty: E ...

  5. Leetcode 313. super ugly number

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  6. Leetcode 264. Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  7. LeetCode 263 Ugly Number

    Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...

  8. [LeetCode] Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  9. [LeetCode] Ugly Number

    Ugly Number Total Accepted: 20760 Total Submissions: 63208 Difficulty: Easy Write a program to check ...

随机推荐

  1. 使用对象,面向对象创建div的方式

    <script> // //对象div的创建 // var div = document.createElement("div"); // document.body. ...

  2. javaweb上传文件夹

    我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...

  3. Error Codes Messages查找工具介绍

    当我们通过各种手段获取到一个Windows错误码后,如何获取对应的错误消息呢?有两种方法:一是用编程的手段(FormatMessage):其二是用现成的工具.第一种方法一般在我们编码的时候有用,而更多 ...

  4. kubefuse 让Kubernetes 资源成为fuse 文件系统

    kubefuse 是基于fuse 开发的文件系统,我们可以像访问文件系统一样访问Kubernetes 资源,使用python开发 支持以下特性: 可以使用方便的linux tools: ls. vim ...

  5. C++语言第一课的学习

    // HelloApp.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include ...

  6. (2)React的开发

    实例: import React from 'react'; class TodoList extends React.Component { constructor(props){ super(pr ...

  7. 使用Xpose突破安卓App禁止截屏限制

    WindowManager.LayoutParams.FLAG_SECURE标志的app,这里需要注意下支付宝.网上银行类的app不建议拦截,像支付宝里的付款码,商家拿到后,直接就能扣费,不需要用户这 ...

  8. 请在mysql配置文件修sql-mode或sql_mode为NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    错误信息:请在mysql配置文件修sql-mode或sql_mode为NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 解决办法(最有效,以MySQL5.7为例): ...

  9. posh-git

    https://github.com/dahlbyk/posh-git#step-2-import-posh-git-from-your-powershell-profile $profile.All ...

  10. 【阿里云IoT+YF3300】9.快速开发modbus设备驱动

    Modbus是一种串行通信协议,是莫迪康公司为PLC(编程逻辑控制器)通信而设计的协议.Modbus目前已经成为工业领域通信协议的业界标准,大部分的仪器仪表都支持该通信协议.很早以前就开发过基于Mod ...