99클럽 코테 스터디 4일차 TIL + 문자열
2024. 10. 31. 11:37ㆍAlgorithm Problem Solving
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 알고리즘! 생각해보자
1) replace 문자열 to 숫자
2) 문자열을 숫자로 parseInt
2. 해결 코드
class Solution {
public int solution(String s) {
int answer = 0;
String[] numbers = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
for(int i=0; i<numbers.length; i++) {
s = s.replaceAll(numbers[i], Integer.toString(i));
}
answer = Integer.parseInt(s);
return answer;
}
}
3. 레퍼런스
[Java] 프로그래머스 숫자 문자열과 영단어
[Java] 프로그래머스 숫자 문자열과 영단어
velog.io
'Algorithm Problem Solving' 카테고리의 다른 글
99클럽 코테 스터디 9일차 TIL + 해시 (0) | 2024.11.05 |
---|---|
99클럽 코테 스터디 5일차 TIL + 해시 (0) | 2024.11.01 |
99클럽 코테 스터디 3일차 TIL + 문자열 (0) | 2024.10.30 |
99클럽 코테 스터디 2일차 TIL + 문자열 (1) | 2024.10.29 |
99클럽 코테 스터디 1일차 TIL + 문자열 (1) | 2024.10.28 |