Skip to content

Commit 257bda5

Browse files
committed
Add 728 link
1 parent 1c8b683 commit 257bda5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ I'm currently working on [Analytics-Zoo](https://github.com/intel-analytics/anal
189189
| 717 | [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/717_1-bit_and_2-bit_Characters.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/717_1-bit_and_2-bit_Characters.java) | 1. Go through bits, 1 skip next, O(n) and O(1)<br>2. Find second last zero reversely, O(n) and O(1) |
190190
| 720 | [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/720_Longest_Word_in_Dictionary.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/720_Longest_Word_in_Dictionary.java) | 1. Brute Force, O(sum(w^2)) and O(w)<br>2. Tire Tree, O(sum(w) and O(w))<br>3. Sort and word without last char, O(nlogn + sum(w)) and O(w) |
191191
| 724 | [Find Pivot Index](https://leetcode.com/problems/find-pivot-index/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/724_Find_Pivot_Index.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/724_Find_Pivot_Index.java) | Seach the array to find a place where left sum is equal to right sum, O(n) and O(1) |
192+
| 728 | [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers/solution/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/728_Self_Dividing_Numbers.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/728_Self_Dividing_Numbers.java) | Brute Force check every digit, O(nlogD) and O(1) |
192193
| 733 | [Flood Fill](https://leetcode.com/problems/flood-fill/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/733_Flood_Fill.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/733_Flood_Fill.java) | 1. DFS with stack or recursive, O(n) and O(n)<br>2. BFS with queue, O(n) and O(n) |
193194
| 743 | [Network Delay Time](https://leetcode.com/problems/network-delay-time/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/743_Network_Delay_Time.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/743_Network_Delay_Time.java) | Let V == N, then: 1. DFS, O(V^V+ElgE), O(V+E)<br>2. Dijkstra, O(V^2+E), O(V+E)|
194195
| 751 | [IP to CIDR](https://leetcode.com/problems/ip-to-cidr/) &hearts; | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/751_IP_to_CIDR.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/751_IP_to_CIDR.java) | Bit manipulations, incrementail is 1 << (32 - mask) |

java/728_Self_Dividing_Numbers.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
class Solution {
2-
public List<Integer> selfDividingNumbers(int left, int right)
3-
{
2+
public List<Integer> selfDividingNumbers(int left, int right) {
43
LinkedList list = new LinkedList();
5-
for(int i = left; i <= right; i++)
6-
{
4+
for(int i = left; i <= right; i++) {
75
if(isSelfDiving(i))
86
list.add(i);
97
}
108
return list;
119
}
1210

13-
public boolean isSelfDiving(int num)
14-
{
11+
public boolean isSelfDiving(int num) {
1512
int digit = num % 10;
1613
int temp = num;
1714
boolean isTrue = true;
18-
while(temp != 0)
19-
{
20-
if(digit == 0 || num % digit != 0)
21-
{
15+
while(temp != 0) {
16+
// 0 is special
17+
if(digit == 0 || num % digit != 0) {
2218
isTrue = false;
2319
break;
24-
}
25-
else
26-
{
20+
} else {
2721
temp /= 10;
28-
digit = temp%10;
22+
digit = temp % 10;
2923
}
3024
}
3125
return isTrue;
32-
3326
}
34-
3527
}

python/728_Self_Dividing_Numbers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
3+
# check every digit
4+
return [x for x in range(left, right+1) if all([int(i) != 0 and x % int(i)==0 for i in str(x)])]
5+
6+
# def selfDividingNumbers(self, left: int, right: int) -> List[int]:
7+
# return [x for x in range(left, right+1) if all((i and (x % i==0) for i in map(int, str(x))))]

0 commit comments

Comments
 (0)