목록분류 전체보기 (146)
무냐의 개발일지
보호되어 있는 글입니다.

* 시간복잡도 비교 (worst case) 배열 한방향 연결리스트 양방향 연결리스트 읽기/쓰기 O(1) moveAfter/ Before O(n) O(1) pushFront (insert 라고 보면 될듯) O(n) O(1) O(1) pushBack (append) O(1) O(n) O(1) popFront (pop(0)) O(n) O(1) O(1) popBack (pop) O(1) O(n) O(1) Insert (insert(3)) O(n) O(n) O(1) Remove (remove) O(n) O(n) O(1) Search O(n) O(n) O(n) Index/ Count O(n) append, pop 연산이 평균 O(1)시간이다. resize가 일어나지 않는 한 O(1) 걸리고, append할 때마다 ..
69. Sqrt(x) 내가 직관적으로 푼 건 아래와 같은데, 소요시간이 좀 더 길게 나왔다 # if cannot use **0.5 class Solution: def mySqrt(self, x): # 1,4,9,16,25,36,49,64,81,100 # 1(3), 2(5), 3(7), 4(9), 5(11), 6(13)... 홀수개다 for i in range(x+1): if x in range(i**2, ((i+1)**2)): return int(i) 좀 더 모범적인 답안은 아래와 같다 class Solution: def mySqrt(self, x: int) -> int: left,right=1,x while leftx: right=mid-1 else: left=mid+1 return right 1689..
df.rename(columns = {"level_0": "Feature 1", "level_1": "Feature 2", 0: 'Correlation Coefficient'}, inplace=True) import pandas as pd def renameColumns(students: pd.DataFrame) -> pd.DataFrame: students.rename(columns={'id' : 'student_id', 'first' : 'first_name', 'last' : 'last_name', 'age' : 'age_in_years'},inplace = True) return students 1. Two Sum class Solution: def twoSum(self, nums: List[in..
| Array에서 정렬하는 파라미터 Key #sorted에 아무런 key값 주지 않을 경우, 기본 ascending으로 출력 array = [3, 1, 5, 2, 4] sorted_array = sorted(array) print(sorted_array) # 출력: [1, 2, 3, 4, 5] #key=lambda x: x[0] #튜플에서 각 첫번째 요소 기준으로, 오름차순 정렬 array = [(1, 'b'), (3, 'a'), (2, 'c')] sorted_array = sorted(array, key=lambda x: x[0]) print(sorted_array) # 출력: [(1, 'b'), (2, 'c'), (3, 'a')] #key=len #문자열의 길이에 따른 정렬 array = ['appl..
와 이거 진짜 오래걸렸네 ㅜㅜㅜ 흑흑 그래도 끈질기게 해서 결국 해냈다 !!!! 첫번째 방법 #정상작동하는 코드 Operators = ['+', '-', '*', '/', '(', ')', '^'] # collection of Operators Priority = {'+':1, '-':1, '*':2, '/':2, '^':3} # dictionary having priorities of Operators def infixToPostfix(expression): stack = [] # initialization of empty stack output = '' for character in expression: if character not in Operators: #숫자/문자들은 결과에 추가 output+..

(점프 투 파이썬) (파이썬 300제) # 클래스는 타입을 만드는 도구디 class Calculator: def __init__(self): self.result=0 def add(self, num): self.result += num return self.result cal1 = Calculator() cal2 = Calculator() print(cal1.add(3)) print(cal1.add(5)) print(cal2.add(6)) print(cal2.add(8)) 결과 : 3 8 6 14 Calculator : 클래스 cal1, cal2 : 객체 클래스 안에 구현된 함수는 다른 말로 메서드(method)라고 부른다. setdata 메서드에는 self, first, second 총 3개의 매개변수..

1. Stacks (LIFO) 쌓여있는 형태 (책을 쌓아놓은 형태) 나중에 들어간게 먼저 나온다 Abstract data type - Push (Key) : adds key to collection - Key Top() : returns most recently-added key - Key Pop() : removes and returns most recently-added key - Boolean Empty() : are there any elements? stack은 이 balance를 track 하기 좋은 방법이다 이용 : compiler, 많은 알고리즘에 사용된다 모든 짝이 맞을 때 pop하면서 사라지는 코드 Push(a) - Push(b) - Top() : b - Push(c) - Pop() :..