Skip to content

Commit

Permalink
Create 26-find-the-pivot-integer.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jun 26, 2023
1 parent ba59d4d commit d831157
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 2023/06/26-find-the-pivot-integer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
impl Solution {
pub fn pivot_integer(n: i32) -> i32 {
let x = ((n * (n + 1) / 2) as f64).sqrt() as i32;
if x * x == (n * (n + 1) / 2) { x } else { -1 }
}
}

0 comments on commit d831157

Please sign in to comment.