본문 바로가기

분류 전체보기

(52)
List comprehension vs. map List comprehension vs map Is there a reason to prefer using map() over list comprehension or vice versa? Is either of them generally more efficient or considered generally more Pythonic than the other? stackoverflow.com 람다 없이 같은 함수를 쓴다면 map이 조금 더 빠르고, 람다로 함수를 선언한다면 list comprehension이 조금 더 빠르다.
[LeetCode/Easy] 88. Merge Sorted Array 88. Merge Sorted Array 통과하지 못한 이유를 종합적으로 생각해 봤을 때, 답안 예시와 같은 approach를 생각했으나 이진 탐색으로 풀어보려고 해서 더 어려웠던 것으로 보인다. 처음부터 (상대적으로) 난이도가 어려운 알고리즘으로 풀려고 하지 말고, time complexity가 어떻든 반복문으로 이해하기 쉽게 구현해 보자. 그 이후에 time complexity를 줄일 방법을 생각해 보자. 즉, 문제를 풀 때 어려운 방법보다는 쉽고 단순한 방법으로 먼저 접근하고 이후 효율화하자. 효율화할 때 time/space complexity를 줄일 수 있는 조건문의 논리연산자를 고민해 보자. 같은 말을 두 번 체크하고 있을 수도 있다. 내 풀이 vs. 답안 풀이 내 풀이 답안 풀이 in-plac..
[LeetCode/Easy] 121. Best Time to Buy and Sell Stock 121. Best Time to Buy and Sell Stock 내 풀이 vs. 답안 풀이 내 풀이 답안 풀이 prices 길이가 1일 때 return 0 if len(prices) == 1: return 0 else: for i in range(len(prices)): # 이하 생략 max_profit = 0 for i in range(len(prices) - 1): for j in range(len(prices)) # 이하 생략 return max_profit -> i는 마지막 원소를 돌지 않게끔 하면 if문으로 확인할 필요 없음 최대 profit을 구하는 방식 profits = [] profits.append(profit) return max(profits) -> max(), min() 없이 최대..
Batch Normalization Understanding Batch Normalization with Examples in Numpy and Tensorflow with Interactive Code So for today, I am going to explore batch normalization (Batch Normalization: Accelerating Deep Network Training by Reducing Internal… towardsdatascience.com Normalization vs. Standardization 참고로, 표준화와 정규화는 데이터의 스케일을 조정해 다루기 쉽게 만들어줄 뿐 데이터의 분포 모양을 변경하지는 않음 -> sklearn.preprocessing.StandardScaler, sklearn..
[LeetCode/Easy] 20. Valid Parentheses 20. Valid Parentheses easy 문제는 아직까지 모르는 개념은 거의 없고, 이 문제를 어떤 자료 구조로 풀어야 효과적일지가 포인트인 것 같다. 따라서 내가 아는 알고리즘 중에 풀 수 없을까 고민해보자!!! 내 풀이 vs. 답안 풀이 내 풀이 답안 풀이 주어진 test case 외의 case {()}[] 에 대한 이해 (= 문제 이해) {()}[] 와 같은 예시는 invalid하다 생각함. 왜냐하면 바로 닫혀야 한다고 문제를 잘못 이해했기 때문. 주어진 예시 외에도 valid한지 invalid한지 판단할 수 있어야 하는데.. -> 근거에 대해서도 설명할 수 있어야 함. 생각만 하지 말고 말로 설명해보기! 설명할 수 없으면 아닌 것. {()}[]와 같은 예시는 valid함. 왜냐하면 꼭 연속..