2270. Number of Ways to Split Array
Problem
2270. Number of Ways to Split Array
Approach
2 <= nums.length <= 10^5, so we can directly take the first element. The initial state has the pointer at index 0, about to move to index 1. A single for loop is all we need.
The second method is the key one — taken from the editorial.
Code
class Solution:
def waysToSplitArray(self, nums: List[int]) -> int:
temp_sum = nums[0]
total_sum = sum(nums) - temp_sum
ans = 0
for i in range(1, len(nums)):
if temp_sum >= total_sum:
ans += 1
temp_sum += nums[i]
total_sum -= nums[i]
return anst = (sum(nums) + 1) // 2
return sum(s >= t for s in accumulate(nums[:-1]))最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0
2241. Design an ATM Machine
LeetCode 2241. Design an ATM Machine — solution using a greedy algorithm to simulate ATM deposit and withdrawal logic. The core technique is iterating denominations in reverse (500→20) with a hash map tracking banknote counts, always using the largest denomination first. Suitable for CS/AI job seekers preparing for system design interviews or practicing medium-difficulty simulation problems.
One question daily 2293. Great mini game
LeetCode 2293. 极大极小游戏 题解 — 通过递归思想将一维数组不断转化为二维数组操作,避免索引变化混乱;利用 flag 计数交替取最大值与最小值,适合正在刷简单题、巩固递归与数组处理技巧的算法初学者。