Saturday, March 20, 2021

Leetcode Everyday: 728. Self Dividing Numbers. Easy

public class Solution {
    public IList<int> SelfDividingNumbers(int left, int right) {
        var list = new List<int>();
        for (var i = left; i <= right; ++i) {
            for (var n = i; n > 0; n /= 10) {
                var toDivide = n % 10;
                if (toDivide == 0 || i % toDivide != 0) {
                    goto goNextNumber;
                }                
            }
            list.Add(i);
            
goNextNumber:;
        }
        return list;
    }
}
Source: https://leetcode.com/problems/self-dividing-numbers/

No comments:

Post a Comment