1480 - Running Sum of 1d Array
MASALA SHARTI: LINK
Inglizcha: Given an array nums
. We define a running sum of an array as runningSum[i] = sum(nums[0]β¦nums[i])
.
Return the running sum of nums
.
O'zbekcha: nums
array berilgan. Biz nums
array yig'indisini quyidagicha hisoblab runningSum[i] = sum(nums[0]β¦nums[i])
.
nums
ning yig'indisi qaytarilsin.
Misol 1
Misol 2
Misol 3
Cheklovlar
1 <= nums.length <= 1000
-10^6 <= nums[i] <= 10^6
- Yechim: LINK
Masala shartiga ko'ra nums[i]
elementi o'zidan oldingi elementlar yig'indisiga tenglab chiqishimiz kerak. Shu sababli 1
dan n
gacha sikl ochamiz. Sababi 0
dan boshlashimiz shart emas 0
- elementdan oldin boshqa qiymat yo'q va har bir yurishida biz nums[i] = nums[i] + nums[i - 1]
ga tenglab boramiz.
Natija sifatida nums
ni o'zini qaytarib yuboramiz.
Time Complexity: O(n - 1)
Space Complexity: O(1)
Oxirgi yangilanish:
November 13, 2022 09:15:23