Skip to content

Commit bf0113d

Browse files
committed
feat: add solutions to lc problem: No.1317
1 parent bc8aa8f commit bf0113d

File tree

6 files changed

+128
-12
lines changed

6 files changed

+128
-12
lines changed

solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ tags:
9696
```python
9797
class Solution:
9898
def getNoZeroIntegers(self, n: int) -> List[int]:
99-
for a in range(1, n):
99+
for a in count(1):
100100
b = n - a
101-
if "0" not in str(a) + str(b):
101+
if "0" not in f"{a}{b}":
102102
return [a, b]
103103
```
104104

@@ -159,6 +159,22 @@ function getNoZeroIntegers(n: number): number[] {
159159
}
160160
```
161161

162+
#### Rust
163+
164+
```rust
165+
impl Solution {
166+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
167+
for a in 1..n {
168+
let b = n - a;
169+
if !a.to_string().contains('0') && !b.to_string().contains('0') {
170+
return vec![a, b];
171+
}
172+
}
173+
vec![]
174+
}
175+
}
176+
```
177+
162178
<!-- tabs:end -->
163179

164180
<!-- solution:end -->
@@ -178,14 +194,14 @@ function getNoZeroIntegers(n: number): number[] {
178194
```python
179195
class Solution:
180196
def getNoZeroIntegers(self, n: int) -> List[int]:
181-
def f(x):
197+
def f(x: int) -> bool:
182198
while x:
183199
if x % 10 == 0:
184200
return False
185201
x //= 10
186202
return True
187203

188-
for a in range(1, n):
204+
for a in count(1):
189205
b = n - a
190206
if f(a) and f(b):
191207
return [a, b]
@@ -281,6 +297,32 @@ function getNoZeroIntegers(n: number): number[] {
281297
}
282298
```
283299

300+
#### Rust
301+
302+
```rust
303+
impl Solution {
304+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
305+
fn f(mut x: i32) -> bool {
306+
while x > 0 {
307+
if x % 10 == 0 {
308+
return false;
309+
}
310+
x /= 10;
311+
}
312+
true
313+
}
314+
315+
for a in 1..n {
316+
let b = n - a;
317+
if f(a) && f(b) {
318+
return vec![a, b];
319+
}
320+
}
321+
vec![]
322+
}
323+
}
324+
```
325+
284326
<!-- tabs:end -->
285327

286328
<!-- solution:end -->

solution/1300-1399/1317.Convert Integer to the Sum of Two No-Zero Integers/README_EN.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ The time complexity is $O(n \times \log n)$, where $n$ is the integer given in t
7575
```python
7676
class Solution:
7777
def getNoZeroIntegers(self, n: int) -> List[int]:
78-
for a in range(1, n):
78+
for a in count(1):
7979
b = n - a
80-
if "0" not in str(a) + str(b):
80+
if "0" not in f"{a}{b}":
8181
return [a, b]
8282
```
8383

@@ -138,6 +138,22 @@ function getNoZeroIntegers(n: number): number[] {
138138
}
139139
```
140140

141+
#### Rust
142+
143+
```rust
144+
impl Solution {
145+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
146+
for a in 1..n {
147+
let b = n - a;
148+
if !a.to_string().contains('0') && !b.to_string().contains('0') {
149+
return vec![a, b];
150+
}
151+
}
152+
vec![]
153+
}
154+
}
155+
```
156+
141157
<!-- tabs:end -->
142158

143159
<!-- solution:end -->
@@ -157,14 +173,14 @@ The time complexity is $O(n \times \log n)$, where $n$ is the integer given in t
157173
```python
158174
class Solution:
159175
def getNoZeroIntegers(self, n: int) -> List[int]:
160-
def f(x):
176+
def f(x: int) -> bool:
161177
while x:
162178
if x % 10 == 0:
163179
return False
164180
x //= 10
165181
return True
166182

167-
for a in range(1, n):
183+
for a in count(1):
168184
b = n - a
169185
if f(a) and f(b):
170186
return [a, b]
@@ -260,6 +276,32 @@ function getNoZeroIntegers(n: number): number[] {
260276
}
261277
```
262278

279+
#### Rust
280+
281+
```rust
282+
impl Solution {
283+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
284+
fn f(mut x: i32) -> bool {
285+
while x > 0 {
286+
if x % 10 == 0 {
287+
return false;
288+
}
289+
x /= 10;
290+
}
291+
true
292+
}
293+
294+
for a in 1..n {
295+
let b = n - a;
296+
if f(a) && f(b) {
297+
return vec![a, b];
298+
}
299+
}
300+
vec![]
301+
}
302+
}
303+
```
304+
263305
<!-- tabs:end -->
264306

265307
<!-- solution:end -->
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Solution:
22
def getNoZeroIntegers(self, n: int) -> List[int]:
3-
for a in range(1, n):
3+
for a in count(1):
44
b = n - a
5-
if "0" not in str(a) + str(b):
5+
if "0" not in f"{a}{b}":
66
return [a, b]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
3+
for a in 1..n {
4+
let b = n - a;
5+
if !a.to_string().contains('0') && !b.to_string().contains('0') {
6+
return vec![a, b];
7+
}
8+
}
9+
vec![]
10+
}
11+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Solution:
22
def getNoZeroIntegers(self, n: int) -> List[int]:
3-
def f(x):
3+
def f(x: int) -> bool:
44
while x:
55
if x % 10 == 0:
66
return False
77
x //= 10
88
return True
99

10-
for a in range(1, n):
10+
for a in count(1):
1111
b = n - a
1212
if f(a) and f(b):
1313
return [a, b]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
impl Solution {
2+
pub fn get_no_zero_integers(n: i32) -> Vec<i32> {
3+
fn f(mut x: i32) -> bool {
4+
while x > 0 {
5+
if x % 10 == 0 {
6+
return false;
7+
}
8+
x /= 10;
9+
}
10+
true
11+
}
12+
13+
for a in 1..n {
14+
let b = n - a;
15+
if f(a) && f(b) {
16+
return vec![a, b];
17+
}
18+
}
19+
vec![]
20+
}
21+
}

0 commit comments

Comments
 (0)