Straightforward Java Solution


  • 0
    R
    
    class Solution {
        public List<Integer> selfDividingNumbers(int left, int right) {
            List<Integer> selfDivNum = new ArrayList<>();
            for(int i = left;i<=right;i++){
                int num = i;
                boolean flag = true;
                while(num!=0){
                    int rev = num%10;
                    if((rev == 0) || (i%rev != 0)) {
                        flag = false;
                        break;
                    }
                    num/=10;
                }
                if(flag) selfDivNum.add(i);
            }
            return selfDivNum;
        }
    }
    
    

Log in to reply
 

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