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

leetcode-728-easy

时间:2022-10-26 19:03:54浏览次数:36  
标签:right dividing int self number easy leetcode 728 left

Self Dividing Numbers

A self-dividing number is a number that is divisible by every digit it contains.

For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
A self-dividing number is not allowed to contain the digit zero.

Given two integers left and right, return a list of all the self-dividing numbers in the range [left, right].

Example 1:

Input: left = 1, right = 22
Output: [1,2,3,4,5,6,7,8,9,11,12,15,22]
Example 2:

Input: left = 47, right = 85
Output: [48,55,66,77]
Constraints:

1 <= left <= right <= 104

思路一:遍历区间,对每个数字进行判断

public List<Integer> selfDividingNumbers(int left, int right) {
    List<Integer> result = new ArrayList<>();

    for (int i = left; i <= right; i++) {
        if (selfDividingNumber(i)) result.add(i);
    }
    return result;
}

private static boolean selfDividingNumber(int num) {
    int temp = num;
    while (num > 0) {
        int x = num % 10;
        if (x == 0 || temp % x != 0) return false;
        num /= 10;
    }

    return true;
}

标签:right,dividing,int,self,number,easy,leetcode,728,left
From: https://www.cnblogs.com/iyiluo/p/16829646.html

相关文章

  • leetcode-392-easy
    IsSubsequenceGiventwostringssandt,returntrueifsisasubsequenceoft,orfalseotherwise.Asubsequenceofastringisanewstringthatisformed......
  • leetcode-476-easy
    NumberComplementThecomplementofanintegeristheintegeryougetwhenyouflipallthe0'sto1'sandallthe1'sto0'sinitsbinaryrepresentation.Fo......
  • leetcode-1313-easy
    DecompressRun-lengthEncodedListWearegivenalistnumsofintegersrepresentingalistcompressedwithrun-lengthencoding.Considereachadjacentpairo......
  • leetcode-292-easy
    NimGameYouareplayingthefollowingNimGamewithyourfriend:Initially,thereisaheapofstonesonthetable.Youandyourfriendwillalternatetaking......
  • leetcode-599-easy
    MinimumIndexSumofTwoListsGiventwoarraysofstringslist1andlist2,findthecommonstringswiththeleastindexsum.Acommonstringisastringthat......
  • 视频融合平台EasyCVR通道播放时提示channle异常是什么原因?该如何解决?
    EasyCVR视频融合平台部署轻快、功能灵活,在视频能力上,可提供视频直播、录像、回放、检索、云存储、级联、告警等功能。平台可支持多协议、多类型设备接入,包括国标GB28181、R......
  • 视频融合平台EasyCVR如何优化web页面卡顿情况?
    EasyCVR具备强大的视频接入、汇聚与管理、视频分发等视频能力,可实现的视频功能包括:视频监控直播、云端录像、云存储、录像检索与回看、智能告警、平台级联、服务器集群、智......
  • #yyds干货盘点# leetcode-136 只出现一次的数字
    本题可以用异或运算,规则是同0,最后剩下的数字就是只出现一次的数字/**<p>给定一个<strong>非空</strong>整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出......
  • #yyds干货盘点# leetcode-136 只出现一次的数字
    本题可以用异或运算,规则是同0,最后剩下的数字就是只出现一次的数字/**<p>给定一个<strong>非空</strong>整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出......
  • 【leetcode_C++_字符串_day7】344_反转字符串&541_反转字符串II&&剑指Offer_05_替换空
    344.反转字符串编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组s的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用O(1)......