-
프로그래머스 - 숫자 문자열과 영단어 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 22:06
- 문제 링크 : 숫자 문자열과 영단어
정답
import java.util.*; class Solution { public int solution(String s) { int answer = 0; Map<String, Integer> numberMap = new HashMap<>(); numberMap.put("zero", 0); numberMap.put("one", 1); numberMap.put("two", 2); numberMap.put("three", 3); numberMap.put("four", 4); numberMap.put("five", 5); numberMap.put("six", 6); numberMap.put("seven", 7); numberMap.put("eight", 8); numberMap.put("nine", 9); for(String number : numberMap.keySet()){ s = s.replaceAll(number, String.valueOf(numberMap.get(number)) ); } return Integer.valueOf(s); } }
분석
단순 replaceAll
반응형