Grocery Shopping List 구현
데이터 구조 예시:
# 간단한 쇼핑 리스트 클래스
class GroceryList:
def __init__(self):
self.items = {}
def add_item(self, item):
self.items[item] = False # False는 체크되지 않은 상태
def delete_item(self, item):
if item in self.items:
del self.items[item]
def cross_off_item(self, item):
if item in self.items:
self.items[item] = True
def get_list(self):
return self.items
사용 예시:
gl = GroceryList()
gl.add_item("Milk")
gl.add_item("Eggs")
gl.cross_off_item("Milk")
gl.delete_item("Eggs")
print(gl.get_list())
# 출력: {'Milk': True}
'job 인터뷰 > 코테(Matroid) 준비' 카테고리의 다른 글
| 653. Two Sum IV - Input is a BST (0) | 2025.04.17 |
|---|---|
| 271. Encode and Decode Strings (0) | 2025.04.17 |
| 557. Reverse Words in a String III (0) | 2025.04.17 |
| 239. Sliding Window Maximum ★ (0) | 2025.04.16 |
| Matroid 관련 LeetCode 문제 번호 정리 (0) | 2025.04.15 |