日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

728. Self Dividing Numbers

發布時間:2025/4/5 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 728. 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.

Also, a self-dividing number is not allowed to contain the digit zero.

Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.

Example 1:

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

?

Note:

  • The boundaries of each input argument are?1 <= left <= right <= 10000.

解題思路:

一直思考有沒有什么技巧,思考半天,沒有頭緒,最后使用暴力枚舉。

代碼:

1 class Solution { 2 public: 3 vector<int> selfDividingNumbers(int left, int right) { 4 vector<int> ret; 5 for (int i = left; i <= right; ++i) { 6 if (check(i)) 7 ret.push_back(i); 8 } 9 return ret; 10 } 11 bool check(int num) { 12 int tmp = num; 13 while (tmp != 0) { 14 int div = tmp % 10; 15 if (!div) 16 return false; 17 if (num % div != 0) 18 return false; 19 tmp /= 10; 20 } 21 return true; 22 } 23 };

?

轉載于:https://www.cnblogs.com/gsz-/p/9397663.html

總結

以上是生活随笔為你收集整理的728. Self Dividing Numbers的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。