일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 구글로그인
- Spring
- oracle
- 스프링부트
- js
- 자바스크립트
- mysql
- 스프링시큐리티
- SAP ABAP
- java8
- SQL프로그래머스
- kotlin 클래스
- MSA
- SQL
- 스프링
- python
- SQL 문제풀이
- 코틀린 클래스
- javascript
- oauth2
- Leetcode
- spring boot
- springboot
- 스프링부트 채팅서버
- 자바 스트림
- LeetCode SQL
- 프로그래머스
- sap ERP
- pygame
- 오라클
Archives
- Today
- Total
웅겹살의 프로그래밍 삼매경
[알고리즘] 프로그래머스 숫자 문자열과 영단어 - java 본문
728x90
https://programmers.co.kr/learn/courses/30/lessons/81301
코딩테스트 연습 - 숫자 문자열과 영단어
네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자
programmers.co.kr
class Solution {
public int solution(String s) {
String[] num = {"0","1","2","3","4","5","6","7","8","9"};
String[] words = {"zero","one","two","three","four","five","six","seven","eight","nine"};
System.out.println(s);
for(int i=0; i<num.length; i++){
s = s.replace(words[i], num[i]);
}
return Integer.parseInt(s);
}
}
문제에서 주어진 숫자와 영단어를 배열로 선언
for문을 돌면서 대응되는 단어를 숫자로 replace
끝
728x90
'알고리즘' 카테고리의 다른 글
[알고리즘] 문자열 대소문자 변환 (0) | 2022.10.18 |
---|---|
[알고리즘] 문자열 문자 찾기 (0) | 2022.10.18 |
[알고리즘] 프로그래머스 나누어 떨어지는 숫자 배열 - java (1) | 2021.07.27 |
[알고리즘] 프로그래머스 문자열 내 p와 y의 개수 - java (0) | 2021.07.25 |
[알고리즘] 프로그래머스 이상한 문자 만들기 - java (0) | 2021.07.25 |
Comments