분류 전체보기174 [Python 자료구조] 양뱡향 연결 리스트(Doubly Linked Lists) #Node의 구조 확장 # class Node: def __init__(self, item): self.data = item self.prev = None self.next = None #Dummy node class DoublyLinkedList: def __init__(self): self.nodeCount = 0 self.head = Node(None) self.tail = Node(None) self.head.prev = None self.head.next = self.tail self.tail.prev = self.head self.tail.next = None #리스트 순회 def traverse(self): result = [] curr = self.head while curr.next.ne.. 2020. 9. 10. [Python 기초] 선형 배열(Linear Array) #Python 리스트에 활용할 수 있는 연산들 (1) 리스트 길이과 관계 없이 빠르게 실행 결과를 보게되는 연산들 원소 덧붙이기 .append() 원소 하나를 꺼내기 .pop() (2) 리스트의 길이에 비례해서 실행 시간이 걸리는 연산들 원소 삽입하기 .insert() 원소 삭제하기 .del() #리스트에서 원소 찾아내기 Example 1: Input: L = [64, 72, 83, 72, 54] x = 72 Output: [1, 3] Example 2: Input: L = [64, 72, 83, 72, 54] x = 83 Output: [2] Example 3: Input: L = [64, 72, 83, 72, 54] x = 49 Output: [-1] Solution 1: def solution(L,.. 2020. 9. 9. [Python 자료구조] 연결리스트 (Linked List) #자료 구조 정의 #노드 class Node: def __init__(self.item): self.data = item self.next = None #비어있는 연결리스트 class LinkedList: def __init(self) self.nodeCount = 0 self.head = None self.tail = None #연산 정의 (1) 특정 원소 참조 (k번째) #K번째 노드 찾기 #[1][67] -> [2][34] -> [3][58] # 노드의 개수: 3 #Head: 67 #Tail: 58 def getAt(self, pos): if pos self.nodeCount: #pos 번째에 있는 노드를 반환하는 것이 목표 retrun None #pos가 0보다 작거나 노드 개수보다 작으면 없다... 2020. 9. 9. LeetCode 155. Min Stack - Python 155. Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve the minimum element in the stack. Constraints: Methods pop, top and getMin operations will always be called on non-empty stacks. Example: Input [".. 2020. 9. 9. LeetCode 53. Maximum Subarray - Python LeetCode 53. Maximum Subarray - Python Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2.. 2020. 9. 7. [Algorithm] 동적계획법(Dynamic programming) - Brute Force, Kadane’s Algorithm #동적계획법(Dynamic programming) - 복잡한 문제를 간단한 여러 개의 문제로 나누어 푸는 방법 (wikipedia) - Bottom-Up 적 방법 #동적계획법 예제 - nm선 자르기 #nm의 선을 1m나 2m 자르는 방법의 수 #1m 선의 경우 #[1,1,1] => 1가지 #dy[1]=1 #2m 선의 경우 #[1,1,1],[2] => 2가지 #dy[2]=2 #3m 선의 경우 #[1,1,1] => 1가지 #[1,1,1],[2] => 2가지 #1가지(1m선의 경우) + 2가지(2m선의 경우) = 3가지 #dy[3]=3 #4m 선의 경우 #2가지(2m선의 경우) + 3가지(3m선의 경우) = 5가지 #dy[4]=5 n = int(input()) dy=[0]*(n+1) #배열을 만듦 dy[1]=.. 2020. 9. 6. [Python 기초] while 반복문 #while 반복문 - 조건이 참인 동안 계속 반복 c = 5 while c!=0: #c가 0이될 때까지 반복 print(c) c-=1 #c가 5에서 -1 반복 #5 #4 #3 #2 #1 #무한루프 시 CTRL + C 로 빠져나올 수 있음 c = 5 while c: print(c) c-=1 #brak문 while True: response = input() if int(response) % 5 == 0 : #10의 배수일경우 print('5으로 나누었을때 나머지가 0입니다.') break #5으로 나누었을때 나머지가 0인 경우 break문으로 반복문을 중단 #Input: 5 #Out: 5으로 나누었을때 나머지가 0입니다. #continue문 - continue문은 반복문을 중단시키지 않고 다음 반복으로 .. 2020. 9. 6. [Python 기초] 재귀 알고리즘 (recursive algorithms) #종결조건의 중요성 알아보기 #재귀의 간단한 예시 - 1부터 n까지 sum def sum(n): print(n) if n 2020. 9. 6. 2020 Fall Semester Courses All lectures will be conducted online. 1. Machine Learning • Course Project (35%) • Project proposal report and presentation : 10% • Final project presentation: 20% • Final project report: 25% • Final Exam (60%) • “Take home exams” (mix between homework and open-book exam) • Class participation (5%) 2. Big Data Analytics (Python) • Assignment (10%) • Midterm Exam (40%) • Final Exam (40%) • Class.. 2020. 9. 6. [Python 기초] 탐색 (search) #선형탐색 (Linear Search) def linear_search(L,x): i=0 #index i를 0으로 준다 while i < len(L) and L[i] != x: #i가 L리스트의 길이보다 작고, L의 i번째 원소가 x와 같지 않을때 i += 1 #i를 1씩 증가시켜나간다. #원소가 발견되면 i값을 가지고 loop가 종료하게 될 것이기 때문에 #i가 L리스트의 길이보다 짧으면 리스트 안에서 원소를 발견했다는 의미 if i < len(L): return i #발견된 x를 리턴하고 else: return -1 #그렇지 않으면 -1을 리턴한다. S = [3,8,2,7,6,7,6,10,9] linear_search(S,6) #Out: 4 S = [3,8,2,7,6,7,6,10,9] linear_s.. 2020. 9. 6. 이전 1 ··· 5 6 7 8 9 10 11 ··· 18 다음