[Python] 파이썬 자료구조 연산 시간복잡도 정리
리스트 자료형(list) 메서드의 시간복잡도 append, pop(), clear(), length 👉🏻 O(1) ==, !=, insert(), delete, pop(i), del, copy(), in, min(), max(), reverse() 👉🏻 O(n) sort() 👉🏻 O(nLog n) 집합 자료형(set) 메서드의 시간복잡도 add(), in, remove, pop(), clear() 👉🏻 O(1) copy() 👉🏻 O(n) 사전 자료형(dict) 메서드의 시간복잡도 store, len(), del, get, pop(k), clear(), keys(), values()👉🏻 O(1)
2023. 5. 13.
[HackerRank] Connected Cells in a Grid
def bfs(x,y,area,row,column,visited): if area[x][y] != 1 or visited[x][y]: return 0 count = 1 visited[x][y] = True queue = [(x,y)] nx = [-1,1,0,0,-1,-1,1,1] ny = [0,0,-1,1,-1,1,-1,1] while queue: v = queue.pop(0) for i in range(8): temp_x = v[0] + nx[i] temp_y = v[1] + ny[i] if temp_x >= 0 and temp_x = 0 and temp_y < column: if area[temp_x][temp_y] == 1 and not visited[temp_x][..
2023. 5. 12.