-
숫자 문자열과 영단어코딩 테스트/Level 1 2021. 7. 19. 23:05반응형
https://programmers.co.kr/learn/courses/30/lessons/81301
파이썬
def solution(s): table = ('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine') for index, text in enumerate(table): s = s.replace(text, str(index)) return int(s)
golang
import ( "strconv" "strings" ) func solution(s string) (result int) { table := [10]string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} for i, v := range table { s = strings.Replace(s, v, strconv.Itoa(i), -1) } result, _ = strconv.Atoi(s) return }
Java
class Solution { public int solution(String s) { var table = new String[]{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; for (var i = 0; i < 10; i++) s = s.replaceAll(table[i], String.valueOf(i)); return Integer.parseInt(s); } }
반응형