https://leetcode.com/problems/find-the-pivot-integer/description/
Find the Pivot Integer - LeetCode
Find the Pivot Integer - Given a positive integer n, find the pivot integer x such that: * The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists
leetcode.com
1
2
3
4
5
6
7
8
9
10
|
class Solution:
def pivotInteger(self, n: int) -> int:
if n == 1 :
return 1
answer = -1
for i in range(1, n):
if i*(i+1) == int((n)*(n+1)/2+i):
answer = i
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2427. Number of Common Factors (0) | 2023.01.10 |
---|---|
leetcode 2529. Maximum Count of Positive Integer and Negative Integer (0) | 2023.01.10 |
leetcode 2418. Sort the People (0) | 2023.01.09 |
leetcode 2315. Count Asterisks (0) | 2023.01.09 |
leetcode 2367. Number of Arithmetic Triplets (0) | 2023.01.08 |
댓글