File tree 5 files changed +70
-1
lines changed
algorithms/SelfDividingNumbers
5 files changed +70
-1
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ All solutions will be accepted!
7
7
| 771| [ Jewels and Stones] ( https://leetcode-cn.com/problems/jewels-and-stones/description/ ) | [ java/py/js] ( ./algorithms/JewelsAndStones ) | Easy|
8
8
| 657| [ Judge Route Circle] ( https://leetcode-cn.com/problems/judge-route-circle/description/ ) | [ java/py/js] ( ./algorithms/JudgeRouteCircle ) | Easy|
9
9
| 461| [ Hamming Distance] ( https://leetcode-cn.com/problems/hamming-distance/description/ ) | [ java/py/js] ( ./algorithms/HammingDistance ) | Easy|
10
- | 476| [ Number Complement] ( https://leetcode-cn.com/problems/number-complement/description/ ) | [ java/py/js] ( ./algorithms/NumberComplement ) | Easy|
10
+ | 476| [ Number Complement] ( https://leetcode-cn.com/problems/number-complement/description/ ) | [ java/py/js] ( ./algorithms/NumberComplement ) | Easy|
11
+ | 728| [ Self Dividing Numbers] ( https://leetcode-cn.com/problems/self-dividing-numbers/description/ ) | [ java/py/js] ( ./algorithms/SelfDividingNumbers ) | Easy|
Original file line number Diff line number Diff line change
1
+ # Self Dividing Numbers
2
+ This program is easy to solve
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public List <Integer > selfDividingNumbers (int left , int right ) {
3
+ List <Integer > list = new ArrayList <Integer >();
4
+ for (int i = left ; i <= right ; i ++) {
5
+ if (isSelfDividingNumber (i )) {
6
+ list .add (i );
7
+ }
8
+ }
9
+ return list ;
10
+ }
11
+
12
+ private boolean isSelfDividingNumber (int num ) {
13
+ int originNum = num ;
14
+ while (num > 0 ) {
15
+ int mod = num % 10 ;
16
+ if (mod == 0 || originNum % mod != 0 ) {
17
+ return false ;
18
+ }
19
+ num /= 10 ;
20
+ }
21
+ return true ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } left
3
+ * @param {number } right
4
+ * @return {number[] }
5
+ */
6
+ var selfDividingNumbers = function ( left , right ) {
7
+ array = [ ]
8
+ for ( let i = left ; i <= right ; i ++ ) {
9
+ if ( isSelfDividingNumber ( i ) ) {
10
+ array . push ( i )
11
+ }
12
+ }
13
+ return array
14
+ } ;
15
+
16
+ var isSelfDividingNumber = function ( num ) {
17
+ originNum = num
18
+ while ( num > 0 ) {
19
+ mod = num % 10
20
+ if ( mod === 0 || originNum % mod !== 0 ) {
21
+ return false
22
+ }
23
+ num = parseInt ( num / 10 )
24
+ }
25
+ return true
26
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def selfDividingNumbers (self , left , right ):
3
+ """
4
+ :type left: int
5
+ :type right: int
6
+ :rtype: List[int]
7
+ """
8
+ return [num for num in range (left , right + 1 ) if self .isSelfDividingNumber (num )]
9
+
10
+ def isSelfDividingNumber (self , num ):
11
+ origin_num = num
12
+ while num > 0 :
13
+ mod = num % 10
14
+ if mod == 0 or origin_num % mod != 0 :
15
+ return False
16
+ num /= 10
17
+ return True
You can’t perform that action at this time.
0 commit comments