2485. Find the Pivot Integer Easy
1/**
2 * [2485] Find the Pivot Integer
3 *
4 * Given a positive integer n, find the pivot integer x such that:
5 *
6 * The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively.
7 *
8 * Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input.
9 *
10 * <strong class="example">Example 1:
11 *
12 * Input: n = 8
13 * Output: 6
14 * Explanation: 6 is the pivot integer since: 1 + 2 + 3 + 4 + 5 + 6 = 6 + 7 + 8 = 21.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: n = 1
19 * Output: 1
20 * Explanation: 1 is the pivot integer since: 1 = 1.
21 *
22 * <strong class="example">Example 3:
23 *
24 * Input: n = 4
25 * Output: -1
26 * Explanation: It can be proved that no such integer exist.
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= n <= 1000
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/find-the-pivot-integer/
37// discuss: https://leetcode.com/problems/find-the-pivot-integer/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn pivot_integer(n: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2485() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.