PYTHON

PS/LeetCode

[LeetCode] 42. Trapping Rain Water

https://leetcode.com/problems/trapping-rain-water Stack 문제를 보고 valid parenthesis 같은 느낌이 나서 stack으로 풀어야겠다! 라고 접근했는데 대략적인 방법은 맞았지만 실제로 완전히 이해하고 구현하기까지 엄청 오래 걸렸던 문제다..🥲 엄청 헷갈려서 그냥 다 프린트를 찍어보고 나서야 좀 감이 왔다. 일단 스택으로 풀 때 중요한 것은 1) 내려갔다가 다시 올라올 때 물의 양을 계산하는 것 2) 물의 양은 왼쪽, 오른쪽 기둥 중 더 낮은 기둥을 기준으로 계산하는 것 이다. class Solution: def trap(self, height: List[int]) -> int: stack = [] water = 0 for i in range(len(h..

PS/Python

Python - defaultdict

https://docs.python.org/3.3/library/collections.html#defaultdict-objects 8.3. collections — Container datatypes — Python 3.3.7 documentation 8.3. collections — Container datatypes Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple. namedtuple() fact docs..

램램
'PYTHON' 태그의 글 목록