Skip to content

Commit d99c966

Browse files
committed
feat: add rust solution to lc problem: No.1281
No.1281.Subtract the Product and Sum of Digits of an Integer
1 parent 5092222 commit d99c966

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ func subtractProductAndSum(n int) int {
112112
}
113113
```
114114

115+
### **Rust**
116+
117+
```rust
118+
impl Solution {
119+
pub fn subtract_product_and_sum(mut n: i32) -> i32 {
120+
let mut mul = 1;
121+
let mut sum = 0;
122+
while n != 0 {
123+
let num = n % 10;
124+
n /= 10;
125+
mul *= num;
126+
sum += num;
127+
}
128+
mul - sum
129+
}
130+
}
131+
```
132+
115133
### **...**
116134

117135
```

solution/1200-1299/1281.Subtract the Product and Sum of Digits of an Integer/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ func subtractProductAndSum(n int) int {
104104
}
105105
```
106106

107+
### **Rust**
108+
109+
```rust
110+
impl Solution {
111+
pub fn subtract_product_and_sum(mut n: i32) -> i32 {
112+
let mut mul = 1;
113+
let mut sum = 0;
114+
while n != 0 {
115+
let num = n % 10;
116+
n /= 10;
117+
mul *= num;
118+
sum += num;
119+
}
120+
mul - sum
121+
}
122+
}
123+
```
124+
107125
### **...**
108126

109127
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
impl Solution {
2+
pub fn subtract_product_and_sum(mut n: i32) -> i32 {
3+
let mut mul = 1;
4+
let mut sum = 0;
5+
while n != 0 {
6+
let num = n % 10;
7+
n /= 10;
8+
mul *= num;
9+
sum += num;
10+
}
11+
mul - sum
12+
}
13+
}

0 commit comments

Comments
 (0)