출처: https://astrocosmos.tistory.com/202 [ASTROCOSMOS] '분류 전체보기' 카테고리의 글 목록 (4 Page)
본문 바로가기

분류 전체보기17

Python Decorator 설명 Python Decorator¶'@'의 의미 -> 데코레이터 데코레이터란? -> 전달받은 함수의 앞 뒤에 코드를 실행해주는(장식해주는) 것 데코레이터 함수는 우선 장식을 해줄 func을 파라미터로 전달받는다. 그리고 decorated라는 함수를 내부에 만들어주고 이를 리턴해준다. decorated 함수 안에서는 전달받은 함수의 앞 뒤에 실행할 코드를 작성해준다. In [1]: def hello_decorator(func): def decorated(): print('Hello!') func() print('Nice to meet you!') return decorated In [3]: @hello_decorator def hello(): print("I'm Giung".. 2021. 7. 31.
[LeetCode] #2 Longest Substring Without Repeating Characters class Solution(object): def lengthOfLongestSubstring(self, s): dic, res, start, = {}, 0, 0 for i, ch in enumerate(s): # enumerate 함수를 이용해 각 값에 인덱스를 부여해준다. if ch in dic: # 현재 for문에서 판정되고 있는 문자와 동일한 문자가 딕셔너리에 있을 경우 res = max(res, i-start) # 딕셔너리 내 현재까지 문자 요소가 반복되지 않은 문자열의 최대 길이 start = max(start, dic[ch]+1) # 다음 순서로 판정할 문자의 인덱스 dic[ch] = i # 딕셔너리에 문자와 인덱스 추가 return max(res, len(s)-start) # 동일한 문자가.. 2021. 7. 31.
[LeetCode] #1 Increasing Triplet Subsequence class Solution: def increasingTriplet(self, nums): first = float("inf") second = float("inf") for i in range(len(nums)): if nums[i] second: return True return False 2021. 7. 31.
[백준] 5585번 문제: 거스름돈 파이썬 풀이 (BOJ 5585) 백준 5585번: 거스름돈 파이썬 풀이 (BOJ 5585)¶ link: https://www.acmicpc.net/problem/5585¶ In [6]: change = 1000 - int(input()) yen = [500, 100, 50, 10, 5, 1] cnt = 0 for y in yen: if change 2021. 7. 31.