일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 영어원서읽기
- 읽기
- 쓰릴오브파이트
- 개발자
- 30분
- 10분
- 월간
- realclass
- 매일
- Problem Solving
- leetcode
- 뭐든
- FIT XR
- 3줄정리
- Daily Challenge
- English
- Writing
- 스탭퍼
- 프로젝트
- 괜찮음
- 잡생각
- 파비최
- 운동
- 사이드
- 리얼 클래스
- 미드시청
- 만화도
- 영어공부
- 링피트
- 화상영어
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/roman-to-integer/
Roman to Integer - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
4, 9 등을 치환한 뒤, replace를 체인으로 연결해서 풀면 된다.
class Solution:
def romanToInt(self, s: str) -> int:
table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
s = s.replace("IV", "IIII").replace("IX", "VIIII").replace("XL", "XXXX").replace("XC", "LXXXX").replace("CD", "CCCC").replace("CM", "DCCCC")
return sum(map(lambda x: table[x], s))
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.08.17 |
---|---|
Today's Challenge (0) | 2022.08.16 |
Today's Challenge (0) | 2022.08.14 |
Today's Challenge (0) | 2022.08.13 |
Today's Challenge (0) | 2022.08.12 |
Comments