首页 > 其他分享 >leetcode-263-easy

leetcode-263-easy

时间:2022-10-19 07:46:58浏览次数:39  
标签:return int 263 while easy leetcode

Ugly Number
思路一: 从数字中依次去除 2,3,5,查看剩余的值是否为 1

public boolean isUgly(int n) {
    if (n == 0) return false;

    while (n % 2 == 0) {
        n /= 2;
    }

    while (n % 3 == 0) {
        n /= 3;
    }

    while (n % 5 == 0) {
        n /= 5;
    }

    return n == 1;
}

标签:return,int,263,while,easy,leetcode
From: https://www.cnblogs.com/iyiluo/p/16804871.html

相关文章

  • leetcode-217-easy
    ContainsDuplicate思路一:Set检测publicstaticbooleancontainsDuplicate(int[]nums){Set<Integer>set=newHashSet<>();for(intnum:nums){......
  • leetcode-709-easy
    ToLowerCase思路一:遍历,遇到A-Z范围内的char转换到对应a-z范围publicStringtoLowerCase(Strings){if(s==null||s.isEmpty())returns;int......
  • leetcode-415-easy
    AddString思路一:模拟加法运算,字符串前面填零publicStringaddStrings(Stringnum1,Stringnum2){intmax=Math.max(num1.length(),num2.length());nu......
  • leetcode-389-easy
    FindtheDifference思路一:xor两个字符串publiccharfindTheDifference(Strings,Stringt){charresult=0;for(inti=0;i<s.length();i++){......
  • leetcode-226-easy
    InvertBinaryTree思路一:递归,交换左右。这题比较出名,个人感觉面试的题目和实际工作中遇到的问题还是不太一样的,所以一点准备都不做就跑去面试,答不上来很正常。一般能力......
  • leetcode-219-easy
    ContainsDuplicateII思路一:for循环遍历,结果超时publicbooleancontainsNearbyDuplicate(int[]nums,intk){intleft=-1;for(inti=0;i<nums......
  • leetcode-448-easy
    思路一:用数组记录publicList<Integer>findDisappearedNumbers(int[]nums){int[]m=newint[nums.length];for(intnum:nums){if(num-1......
  • leetcode-495-easy
    TeemoAttacking思路一:对两个前后攻击序列,完全分类只可能出现两种情况,只要把重叠的时间都减去,就是所求时间。此分类对三个以上的重叠时间依旧成立没有重叠,攻击时间累......
  • [LeetCode] 1700. Number of Students Unable to Eat Lunch
    Theschoolcafeteriaofferscircularandsquaresandwichesatlunchbreak,referredtobynumbers0and1respectively.Allstudentsstandinaqueue.Eachstu......
  • leetcode 380. Insert Delete GetRandom O(1) O(1) 时间插入、删除和获取随机元素 (
    一、题目大意实现RandomizedSet类:RandomizedSet()初始化RandomizedSet对象boolinsert(intval)当元素val不存在时,向集合中插入该项,并返回true;否则,返回false......