Leetcode
Grammar
- Complexity of Python Operations
- 대체로 널리 알려진 시간 복잡도를 그대로 따르고 있다.
Print variables
print(f"P : {p}") print(f"I have {card.price}")
nonlocal
sys.maxsize
Internal functions
max
,sum
,map
reversed
,sorted
Libraries
heapq
import heapq heapq.heapify(heap) heapq.heappush(heap, v) # Min heap heapq.heappush(heap, -v) # Max heap heapq.heappush(heap, (v1, v2, v3)) heapq.heappop(heap)
re
import re re.split("[!?',;. ]", paragraph.lower()) re.sub("[!?',;. ]+", " ", paragraph.lower()) re.replace(' ', '', paragraph)
random
import random random.randrange(a, b) # a <= N < b random.randint(a, b) # a <= N <= b
string
chr(65) # 'A' ord('B') - ord('A') # 1 "Hello".split() # ["Hello"] "Hello World".split() # ["Hello", "World"] list("Hello") # ['H', 'e', 'l', 'l', 'o'] "Hello".replace("o", "a") # "Hella"
Collections
defaultdict
from collections import defaultdict shown = defaultdict(int) shown = defaultdict(list) shown = defaultdict(dict)
Counter
from collections import Counter counter = Counter(paragraph) items = list(counter.items()) items.sort(key = lambda x: (x[1], x[1]))
from collections import deque queue = deque("0") queue.append("1") queue.appendleft("2") queue.popleft() queue.pop() len(queue)
Table of contents
- Add Two Numbers
- All Nodes Distance K in Binary Tree
- Basic Calculator II
- Best Time to Buy and Sell Stock
- Binary Tree Inorder Traversal
- Binary Tree Zigzag Level Order Traversal
- Container With Most Water
- Copy List with Random Pointer
- Course Schedule II
- Delete Node in a BST
- Group Anagrams
- Insert Delete GetRandom O(1)
- K Closest Points to Origin
- LFU Cache
- LRU Cache
- Longest Palindromic Substring
- Longest Substring Without Repeating Characters
- Merge Intervals
- Merge Two Sorted Lists
- Merge k Sorted Lists
- Most common word
- Number of Islands
- Product of Array Except Self
- Recover Binary Search Tree
- Reorder Data in Log Files
- Rotting Oranges
- Search a 2D matrix II
- Subtree of Another Tree
- Top K Frequent Elements
- Trapping Rain Water
- Two sum
- Valid Parentheses
- Word Ladder