본문 바로가기

python185

[코딩 + 알고리즘 완주반] 13일차. 시간복잡도 # 알고리즘 시간 복잡도 계산이 필요한 이유 하나의 문제를 푸는 알고리즘이 다양함 다양한 알고리즘 중 어느 알고리즘이 더 좋은지를 분석하기 위해 # 알고리즘 복잡도 계산 항목 시간 복잡도 : 알고리즘 실행 속도 공간 복잡도 : 알고리즘이 사용하는 메모리 사이즈 # 알고리즘 시간 복잡도의 주요 요소 입력의 크기가 커지면 커질수록 반복문이 알고리즘 수행시간 지배 # 알고리즘 성능 표기법 Big O (빅 오) 표기법 : 최악의 시행 시간을 표기 오메가 표기법 : 최상의 실행 시간을 표기 세타 표기법 : 평균 실행 시간을 표기 # Big O (빅 오) 표기법 O(n) 입력에 따라 결정되는 시간 복잡도 함수 O(𝑙𝑜𝑔𝑛)의 베이스는 2- log 2 n O(1) < O(𝑙𝑜𝑔𝑛) < O(n) < O(n𝑙𝑜𝑔𝑛) <.. 2021. 3. 27.
[LEET CODE] 232. Implement Queue using Stacks # Problem Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the queue and returns it. int peek() Returns the element at the front of the queu.. 2021. 3. 26.
[LEET CODE] 225. Implement Stack using Queues # Problem Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (push, top, pop, and empty). Implement the MyStack class: void push(int x) Pushes element x to the top of the stack. int pop() Removes the element on the top of the stack and returns it. int top() Returns the element on the top of the stack. boolean.. 2021. 3. 26.
[코딩 + 알고리즘 완주반] 11일차. 배열, 큐 # 꼭 알아둬야 할 자료구조 - 배열 데이터를 나열하고 각 데이터를 인덱스에 대응하도록 구성한 데이터 구조 파이썬에서는 리스트 타입이 배열 기능을 제공하고 있음 장점 - 빠른 접근 가능 단점 - 데이터 추가/삭제가 어렵다 # 파이썬과 배열 파이썬 리스트 활용 # 대표적인 데이터 구조 : 큐 FIFO ( First in First Out) ( 줄을 서는 것과 유사) LILO ( Last In Last Out) # 용어 enqueue : 데이터를 넣는 기능 dequeue : 데이터를 빼는 기능 # 파이썬 큐 라이브러리( import queue ) Queue() : 가장 일반적인 큐 자료 구조 - put, get, qsize LifoQueue() : 나중에 입력된 데이터가 먼저 출력되는 구조(스택구조) - p.. 2021. 3. 25.
[코딩 + 알고리즘 완주반] 11일차. Object Reference # is , __eq__ is, id : id 비교 ( 같은 객체 인지) __eq__, == : 값이 같은지 비교 # 객체 참조 중요한 특징들 # python object reference print("ex1-1") print(dir()) # id vs __eq__ (== 증명) x = {'name':'kim','age':33,'city':'Seoul'} y=x # 얕은 복사 print('ex-2-1 - ', id(x),id(y)) print('ex-2-2 - ', x==y) print('ex-2-3 - ', x is y) print('ex-2-4 - ', x,y) x['class'] = 10 # x가 수정되면 y도 수정됨 print('ex2-5 - ',x,y) print() z = {'name':'ki.. 2021. 3. 25.
❗️[LEET CODE] 316. Remove Duplicate Letters # Problem Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/ Constraints: 1 str: counter, seen, stack = collections.Counter(s), set(), [] for.. 2021. 3. 23.
반응형