LC.P2485[找出中枢整数] 方法一:数学12345678910class Solution { public int pivotInteger(int n) { for (int x = 1; x <= n; ++x) { int a = (1 + x) * x / 2; int b = (x + n) * (n - x + 1) / 2; if (a == b) return x; } return -1; }} 时间复杂度:$O(n)$ 空间复杂度:$O(1)$