https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
|
class Solution:
def maxOperations(self, nums: List[int]) -> int:
first_two = nums[0] + nums[1]
answer = 1
for i in range(1, len(nums)//2):
if nums[i*2] + nums[i*2 + 1] == first_two:
answer +=1
else:
break
return answer
|
cs |
앞에 두개의 합을 계속 비교해나가면 됩니다
반응형
'python-algorithm' 카테고리의 다른 글
백준 31450 Everyone is a winner (0) | 2024.03.31 |
---|---|
백준 31429 SUAPC 2023 Summer (0) | 2024.02.26 |
leetcode 1941. Check if All Characters Have Equal Number of Occurrences (0) | 2024.02.17 |
백준 10798 세로읽기 (1) | 2024.02.15 |
leetcode 1732. Find the Highest Altitude (1) | 2024.02.15 |
댓글