1. 程式人生 > >LeetCode-728-自分割數字

LeetCode-728-自分割數字

class Solution {
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> list = new ArrayList<>();
        for(int i = left;i<=right;i++){
            if(isDivided(i))
                list.add(i);
        }
        return list;
    }
    boolean isDivided(int x){
        int temp = x;
        while(x != 0){
            int rem = x%10;
            if(rem == 0||temp%rem != 0)
                return false;
            x/= 10;
        }
        return true;
    }
}

0和不滿足分割條件的數不能存到集合中