1️⃣ 문제
https://school.programmers.co.kr/learn/courses/30/lessons/81301
2️⃣ 기억해야 했던 개념들
- a.isdigit() : digit인지 판단하는 거 까먹어서 함수로 구현함 (기억하기)
3️⃣ 풀이 과정
- 제한 시간 10초 -> 한번만 N의 복잡도면 충분히 가능하겠다 생각 (단순 구현)
- 순차적으로 문자열 파싱함
4️⃣ 코드
def is_num(a):
if (a == "0" or a == "1" or a == "2" or a == "3" or a =="4" or a == "5" or a == "6" or a == "7" or a == "8" or a == "9"):
return True
else:
return False
def solution(s):
answer = ""
dic = { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}
i = 0
while i < len(s):
a = s[i]
if (a.isdigit()):
answer += a
i += 1
else:
temp = ""
b = i
while (b < len(s) and not is_num(s[b])):
temp += s[b]
b += 1
if (temp in dic):
answer += str(dic[temp])
i = b
break
return int(answer)
'Algorithm > Python' 카테고리의 다른 글
[프로그래머스] 도넛과 막대 그래프 (python) (0) | 2025.09.05 |
---|---|
[알고리즘 스터디] 백준 2164번 Python 풀이 - 카드2 (연산 복잡도, deque, 식 세우기) (0) | 2022.06.03 |
[알고리즘 스터디] 백준 2798번 Python 풀이 - 블랙잭 (0) | 2022.06.03 |
[알고리즘 스터디] 백준 1259번 Python 풀이 - 팰린드롬수 (0) | 2022.05.02 |
[알고리즘 스터디] 백준 10773번 Python 풀이 - list 자료형 다루기 (0) | 2022.04.06 |