• 문제 링크
Self Dividing Numbers - LeetCode
Can you solve this real interview question? Self Dividing Numbers - A self-dividing number is a number that is divisible by every digit it contains. * For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. A self-d
leetcode.com
• 풀이 코드
import java.util.ArrayList;
import java.util.List;
public class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++) if (isSelfDividing(i)) list.add(i);
return list;
}
private boolean isSelfDividing(int i) {
int n = i, d;
do if ((d = n % 10) == 0 || i % d != 0) return false; while ((n /= 10) > 0);
return true;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 733. Flood Fill - Java (0) | 2026.10.06 |
|---|---|
| [LeetCode] 724. Find Pivot Index - Java (0) | 2026.10.04 |
| [LeetCode] 717. 1-bit and 2-bit Characters - Java (0) | 2026.10.03 |
| [LeetCode] 709. To Lower Case - Java (0) | 2026.10.02 |
| [LeetCode] 706. Design HashMap - Java (0) | 2026.10.01 |
댓글