Skip to content

Commit 4a28611

Browse files
authored
feat: add rust solution to lc problem: No.2485 (doocs#1306)
Signed-off-by: xiaolatiao <1628652790@qq.com>
1 parent 2b3ab0c commit 4a28611

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/2400-2499/2485.Find the Pivot Integer/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,23 @@ class Solution {
223223
}
224224
```
225225

226+
### **Rust**
227+
228+
```rust
229+
impl Solution {
230+
pub fn pivot_integer(n: i32) -> i32 {
231+
let y = n * (n + 1) / 2;
232+
let x = (y as f64).sqrt() as i32;
233+
234+
if x * x == y {
235+
return x;
236+
}
237+
238+
-1
239+
}
240+
}
241+
```
242+
226243
### **...**
227244

228245
```

solution/2400-2499/2485.Find the Pivot Integer/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ class Solution {
186186
}
187187
```
188188

189+
### **Rust**
190+
191+
```rust
192+
impl Solution {
193+
pub fn pivot_integer(n: i32) -> i32 {
194+
let y = n * (n + 1) / 2;
195+
let x = (y as f64).sqrt() as i32;
196+
197+
if x * x == y {
198+
return x;
199+
}
200+
201+
-1
202+
}
203+
}
204+
```
205+
189206
### **...**
190207

191208
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn pivot_integer(n: i32) -> i32 {
3+
let y = n * (n + 1) / 2;
4+
let x = (y as f64).sqrt() as i32;
5+
6+
if x * x == y {
7+
return x;
8+
}
9+
10+
-1
11+
}
12+
}

0 commit comments

Comments
 (0)