일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Writing
- 월간
- 스탭퍼
- 화상영어
- FIT XR
- 영어원서읽기
- 뭐든
- 리얼 클래스
- 3줄정리
- 매일
- 링피트
- 괜찮음
- Daily Challenge
- 만화도
- leetcode
- 운동
- 개발자
- 쓰릴오브파이트
- realclass
- 잡생각
- 영어공부
- 미드시청
- 프로젝트
- Problem Solving
- 파비최
- 읽기
- 10분
- 30분
- 사이드
- English
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.04 Today's Challenge 본문
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/
Count Subarrays With Fixed Bounds - LeetCode
Can you solve this real interview question? Count Subarrays With Fixed Bounds - You are given an integer array nums and two integers minK and maxK. A fixed-bound subarray of nums is a subarray that satisfies the following conditions: * The minimum value in
leetcode.com
투 포인터로 푸는 문제.
슬라이딩 윈도우와 투 포인터가 꽤 많이 나오는 솔루션 중에 하나 인듯.
class Solution:
def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int:
answer = 0
minp = maxp = lb = -1
for i, n in enumerate(nums):
if n < minK or n > maxK:
lb = i
if n == minK:
minp = i
if n == maxK:
maxp = i
answer += max(0, min(minp, maxp) - lb)
return answer
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.06 Today's Challenge (0) | 2023.03.06 |
---|---|
2023.03.05 Today's Challenge (0) | 2023.03.05 |
2023.03.03 Today's Challenge (0) | 2023.03.03 |
2023.03.02 Today's Challenge (0) | 2023.03.02 |
2023.03.01 Today's Challenge (0) | 2023.03.01 |
Comments