Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Dinosaur
- 자료구조
- nodejs
- AWS
- Nest.js
- TypeScript
- Express
- Sequelize
- OCR
- class
- 게임
- MongoDB
- dfs
- JavaScript
- mongoose
- cookie
- game
- Queue
- flask
- typeORM
- Python
- Bull
- nestjs
- MySQL
- 정렬
- GIT
- 공룡게임
- react
- jest
Archives
- Today
- Total
포시코딩
[프로그래머스][Lv.0] 영어가 싫어요 본문
728x90
문제
https://school.programmers.co.kr/learn/courses/30/lessons/120894
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
내 풀이
def solution(numbers):
answer_str = ''
number_dict = {
'zero': '0', 'one': '1', 'two': '2', 'three': '3',
'four': '4', 'five': '5', 'six': '6', 'seven': '7',
'eight': '8', 'nine': '9'
}
target = ''
for char in numbers:
target += char
if target in number_dict:
answer_str += number_dict[target]
target = ''
return int(answer_str)
다른 사람 풀이
def solution(numbers):
for num, eng in enumerate(["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]):
numbers = numbers.replace(eng, str(num))
return int(numbers)
와 이 풀이는.. 보고 소름이 돋았다.
인덱스로 활용할 생각을 왜 못했을까..
어렴풋이 글자에 숫자 매칭하는걸 직접 쓰면서
영어 정도면 해당 단어에 맞게 숫자로 바꿔주는 기능 정도 찾아보면 있지 않을까?
어떤 알고리즘이 있지 않을까?
생각했던 나 자신을 반성하게 만들었다.
시간복잡도
시간복잡도는 둘 다 O(N)
728x90
'자료구조알고리즘 > 문제풀이' 카테고리의 다른 글
[프로그래머스][Lv.0] 겹치는 선분의 길이* (0) | 2022.12.16 |
---|---|
[신찬수] 괄호 맞추기 (0) | 2022.12.16 |
[프로그래머스][Lv.0] 캐릭터의 좌표 (0) | 2022.12.14 |
곱하기 or 더하기 (0) | 2022.11.29 |
소수 찾기, 소수의 개수 구하기 (0) | 2022.11.22 |