Skip to content

Commit 255c50f

Browse files
authored
feat: add rust solution to lc problem: No.2240 (#1562)
No.2240.Number of Ways to Buy Pens and Pencils
1 parent 3347ca0 commit 255c50f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ function waysToBuyPensPencils(total: number, cost1: number, cost2: number): numb
122122
}
123123
```
124124

125+
### **Rust**
126+
127+
```rust
128+
impl Solution {
129+
pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 {
130+
let mut ans: i64 = 0;
131+
for pen in 0..=total / cost1 {
132+
ans += ((total - pen * cost1) / cost2) as i64 + 1;
133+
}
134+
ans
135+
}
136+
}
137+
```
138+
125139
### **...**
126140

127141
```

solution/2200-2299/2240.Number of Ways to Buy Pens and Pencils/README_EN.md

+14
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ function waysToBuyPensPencils(total: number, cost1: number, cost2: number): numb
108108
}
109109
```
110110

111+
### **Rust**
112+
113+
```rust
114+
impl Solution {
115+
pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 {
116+
let mut ans: i64 = 0;
117+
for pen in 0..=total / cost1 {
118+
ans += ((total - pen * cost1) / cost2) as i64 + 1;
119+
}
120+
ans
121+
}
122+
}
123+
```
124+
111125
### **...**
112126

113127
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl Solution {
2+
pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 {
3+
let mut ans: i64 = 0;
4+
for pen in 0..=total / cost1 {
5+
ans += ((total - pen * cost1) / cost2) as i64 + 1;
6+
}
7+
ans
8+
}
9+
}

0 commit comments

Comments
 (0)