Skip to content

Commit 8206882

Browse files
Create 2485.py
1 parent 206330e commit 8206882

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

2001-2500/2485.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def pivotInteger(self, n: int) -> int:
3+
tsum = n*(n+1) // 2
4+
l,r = 1,n+1
5+
while l<r:
6+
m = (l+r)//2
7+
lsum = m*(m+1)//2
8+
rsum = tsum-lsum-m
9+
if lsum<rsum:
10+
l=m+1
11+
else:
12+
r=m
13+
return l if l*(l-1)//2==tsum-(l+1)*l//2 else -1

0 commit comments

Comments
 (0)