Skip to content

Commit 979e893

Browse files
committedMay 18, 2021
feat: add solutions to lc problem: No.0970. Powerful Integers
1 parent 651508e commit 979e893

File tree

4 files changed

+105
-5
lines changed

4 files changed

+105
-5
lines changed
 

‎solution/0900-0999/0970.Powerful Integers/README.md

+35-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
<li><code>0 &lt;= bound&nbsp;&lt;= 10^6</code></li>
4545
</ul>
4646

47-
4847
## 解法
4948

5049
<!-- 这里可写通用的实现逻辑 -->
@@ -56,15 +55,48 @@
5655
<!-- 这里可写当前语言的特殊实现逻辑 -->
5756

5857
```python
59-
58+
class Solution:
59+
def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
60+
s = set()
61+
i = 1
62+
while i < bound:
63+
j = 1
64+
while j < bound:
65+
if i + j <= bound:
66+
s.add(i + j)
67+
if y == 1:
68+
break
69+
j *= y
70+
if x == 1:
71+
break
72+
i *= x
73+
return list(s)
6074
```
6175

6276
### **Java**
6377

6478
<!-- 这里可写当前语言的特殊实现逻辑 -->
6579

6680
```java
67-
81+
class Solution {
82+
public List<Integer> powerfulIntegers(int x, int y, int bound) {
83+
Set<Integer> s = new HashSet<>();
84+
for (int i = 1; i < bound; i *= x) {
85+
for (int j = 1; j < bound; j *= y) {
86+
if (i + j <= bound) {
87+
s.add(i + j);
88+
}
89+
if (y == 1) {
90+
break;
91+
}
92+
}
93+
if (x == 1) {
94+
break;
95+
}
96+
}
97+
return new ArrayList<>(s);
98+
}
99+
}
68100
```
69101

70102
### **...**

‎solution/0900-0999/0970.Powerful Integers/README_EN.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,46 @@
4949
### **Python3**
5050

5151
```python
52-
52+
class Solution:
53+
def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
54+
s = set()
55+
i = 1
56+
while i < bound:
57+
j = 1
58+
while j < bound:
59+
if i + j <= bound:
60+
s.add(i + j)
61+
if y == 1:
62+
break
63+
j *= y
64+
if x == 1:
65+
break
66+
i *= x
67+
return list(s)
5368
```
5469

5570
### **Java**
5671

5772
```java
58-
73+
class Solution {
74+
public List<Integer> powerfulIntegers(int x, int y, int bound) {
75+
Set<Integer> s = new HashSet<>();
76+
for (int i = 1; i < bound; i *= x) {
77+
for (int j = 1; j < bound; j *= y) {
78+
if (i + j <= bound) {
79+
s.add(i + j);
80+
}
81+
if (y == 1) {
82+
break;
83+
}
84+
}
85+
if (x == 1) {
86+
break;
87+
}
88+
}
89+
return new ArrayList<>(s);
90+
}
91+
}
5992
```
6093

6194
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<Integer> powerfulIntegers(int x, int y, int bound) {
3+
Set<Integer> s = new HashSet<>();
4+
for (int i = 1; i < bound; i *= x) {
5+
for (int j = 1; j < bound; j *= y) {
6+
if (i + j <= bound) {
7+
s.add(i + j);
8+
}
9+
if (y == 1) {
10+
break;
11+
}
12+
}
13+
if (x == 1) {
14+
break;
15+
}
16+
}
17+
return new ArrayList<>(s);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
3+
s = set()
4+
i = 1
5+
while i < bound:
6+
j = 1
7+
while j < bound:
8+
if i + j <= bound:
9+
s.add(i + j)
10+
if y == 1:
11+
break
12+
j *= y
13+
if x == 1:
14+
break
15+
i *= x
16+
return list(s)

0 commit comments

Comments
 (0)
Please sign in to comment.