PROGRAMMING/[Python] LeetCode3 [LeetCode/Python] Roman to Integer https://leetcode.com/problems/roman-to-integer/ class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ #II -> 2 #MCMXCIV -> M / CM / XC / IV res = 0 #딕셔너리 사용 (값:인덱스) romanint = { 'I' : 1, 'V' : 5, 'X':10, 'L':50, 'C':100, 'D':500, .. 2026. 5. 13. [멘토링] sliding window, two sum 보호되어 있는 글 입니다. 2026. 5. 6. [LeetCode/Python] 1. Two Sum https://leetcode.com/problems/two-sum/description/#배열 nums에서 두 수를 더하면 target이 나온다.#몇 번째, 몇 번째 요소인지 리턴하라#시간복잡도 : O(n)class Solution(object): def twoSum(self, nums, target): #(배열, 결과) dic = {} for i, num in enumerate(nums): #i=인덱스, num=그 위치의 값 want = target - num #지금 값(num)와 더해서 target이 되려면 필요한 값 if want in dic: #.. 2026. 5. 5. 이전 1 다음