일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- English
- 매일
- realclass
- 링피트
- 영어공부
- FIT XR
- 잡생각
- 파비최
- 화상영어
- 사이드
- 프로젝트
- 스탭퍼
- 미드시청
- 리얼 클래스
- 뭐든
- 쓰릴오브파이트
- leetcode
- 읽기
- 월간
- 만화도
- 3줄정리
- 영어원서읽기
- 개발자
- Writing
- 10분
- 30분
- Problem Solving
- Daily Challenge
- 괜찮음
- 운동
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.21 Today's Challenge 본문
https://leetcode.com/problems/number-of-zero-filled-subarrays/
Number of Zero-Filled Subarrays - LeetCode
Can you solve this real interview question? Number of Zero-Filled Subarrays - Given an integer array nums, return the number of subarrays filled with 0. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums =
leetcode.com
DP로 생각했으나, 누적 합으로 쉽게 풀리는 문제.
class Solution:
def zeroFilledSubarray(self, nums: List[int]) -> int:
ans, ns = 0, 0
for num in nums:
if num == 0:
ns += 1
else:
ns = 0
ans += ns
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.23 Today's Challenge (0) | 2023.03.23 |
---|---|
2023.03.22 Today's Challenge (0) | 2023.03.22 |
2023.03.20 Today's Challenge (0) | 2023.03.20 |
2023.03.19 Today's Challenge (0) | 2023.03.19 |
2023.03.18 Today's Challenge (0) | 2023.03.18 |
Comments