日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

728. Self Dividing Numbers

發(fā)布時(shí)間:2025/4/5 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 728. Self Dividing Numbers 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目描述:

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 };

?

轉(zhuǎn)載于:https://www.cnblogs.com/gsz-/p/9397663.html

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。