일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Daily Challenge
- 영어공부
- 파비최
- 괜찮음
- 운동
- Writing
- 리얼 클래스
- 미드시청
- 쓰릴오브파이트
- realclass
- 개발자
- 영어원서읽기
- 프로젝트
- 링피트
- 매일
- 잡생각
- 월간
- 만화도
- 10분
- FIT XR
- English
- 스탭퍼
- 3줄정리
- 뭐든
- Problem Solving
- 읽기
- leetcode
- 화상영어
- 사이드
- 30분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.20 Today's Challenge 본문
https://leetcode.com/problems/can-place-flowers/
Can Place Flowers - LeetCode
Can you solve this real interview question? Can Place Flowers - You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0's and 1'
leetcode.com
근처에 있는 데이터 확인해서 처리
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
cnt = 0
for i in range(len(flowerbed)):
if flowerbed[i] == 0:
elp = (i == 0) or (flowerbed[i-1] == 0)
erp = (i == len(flowerbed) - 1) or (flowerbed[i+1] == 0)
if elp and erp:
flowerbed[i] = 1
cnt += 1
if cnt >= n:
return True
return cnt >= n
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.22 Today's Challenge (0) | 2023.03.22 |
---|---|
2023.03.21 Today's Challenge (0) | 2023.03.21 |
2023.03.19 Today's Challenge (0) | 2023.03.19 |
2023.03.18 Today's Challenge (0) | 2023.03.18 |
2023.03.17 Today's Challenge (0) | 2023.03.17 |
Comments