My easy Java solution


  • 0
    W
     public  List<Integer> selfDividingNumbers(int left, int right) {
    
            if (left > right || left < 0 || right <= 0) {
                return null;
            }
            List<Integer> list = new ArrayList<Integer>();
            for (int i = left; i <= right; i++) {
                addSelfDividingNumber(list, i);
            }
            return list;
        }
    
        private  void addSelfDividingNumber(List<Integer> list, int currentNumber) {
    
            int temp = currentNumber;
            while (temp > 0) {
                int res = temp % 10;
                if (res == 0){
                    return;
                }
                if (currentNumber % res != 0) {
                    return;
                }
                temp /= 10;
            }
            list.add(currentNumber);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.