2485-find-the-pivot-integer

DevGod
Vtuber
/** * @param {number} n * @return {number} */var pivotInteger = function(n) { if(n==1){return 1;} let sum = (n+1)*(n/2); let temp = 0;
for(let I = 0; I<n; I++){ sum += -I; if(sum == temp){ return I; } temp += I; }
return -1;};
class Solution: def pivotInteger(self,n): if n == 1: return 1
sum_total = (n + 1) * (n // 2) temp = 0
for i in range(n): sum_total -= i if sum_total == temp: return i temp += i
return -1