Algorithm3 [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. 이전 1 다음